-
Notifications
You must be signed in to change notification settings - Fork 386
/
app.py
37 lines (28 loc) · 1.16 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import discord
from youtube_search import YoutubeSearch
from disc_conf import TOKEN, PREFIX
client = discord.Client()
# event gets fired when the bot is ready
@client.event
async def on_ready():
print(f'We have logged in as {client.user}')
# gets fired on each msg
@client.event
async def on_message(message):
# if the msg was sent by a bot ignore
if message.author.bot:
return
# if the msg doesnt start with our defined command prefix ignore it
if not message.content.startswith(PREFIX):
return
# Seperate the command and the args
command = message.content[1:].split(' ')[0]
args = message.content[1:].split(' ')[1:]
if command == 'search':
what_to_search = ' '.join(args)
results = YoutubeSearch(what_to_search, max_results=10).to_dict()
link = f'https://www.youtube.com{results[0]["link"]}'
first_result = {'title': results[0]['title'], 'link': link}
# sends the msg back ot the channel with the result
await message.channel.send(f'The First YT Search Result For `{what_to_search}` is: `{first_result["title"]}` and it can be found at {first_result["link"]}')
client.run(TOKEN)