- YouTube Bot is a discord bot where you can search for anything on YouTube, it will automatically find the first result, the channel and a lot more info about it then format it into an embed, and if you would like there is a dropdown menu where you can make the bot send you an ephemeral message with the video as an embed to watch.
- Code Text Editor e.g. VSC (visual studio code)
- Python 3.9.10
- Google API Key
- Your Discord Bot Token
- Get your previously mentioned "Discord Bot Token" and replace the "bottokenhere" with your discord bot token.
- Found here
cmd.run('tokenhere')
- Replace the "googleapikeyhere" found on line 18 with your Google API key
api_service_name = "youtube"
api_version = "v3"
DEVELOPER_KEY = 'googleapikeyhere'
- Now pip install all the modules and you are ready to run your bot!
- You can also host this bot
- To customize your bots status edit the information on line 13
await cmd.change_presence(activity=discord.Activity(name='πΌπΌπΌπΌπΌ', type=5))
- Name is the text that shows up in the status
- The type is what it says before that, e.g. "Streaming", "Listening to" or in this case "Competing in"
- Here are some types you can set it as:
ID | Name | Format | Example |
---|---|---|---|
0 | Game | Playing {name} | "Playing Rocket League" |
1 | Streaming | Streaming {details} | "Streaming Rocket League" |
2 | Listening | Listening to {name} | "Listening to Spotify" |
3 | Watching | Watching {name} | "Watching YouTube Together" |
4 | Custom | {emoji} {name} | ":smiley: I am cool" |
5 | Competing | Competing in {name} | "Competing in Arena World Champions" |
- You can customize the search settings by editing the info found in lines 62-68
request = youtube.search().list(
part="id,snippet",
type='video',
q=f"{output}",
videoDuration='short',
videoDefinition='high',
maxResults=1,
fields="nextPageToken,items(id(videoId),snippet(publishedAt,channelId,channelTitle,title,description))"
)
- and of course you can customize the embed and drop down menu
- How do I avoid maxing out my quota on Googles API?
You should add a cooldown to the bots commands, and if you are using this bot in a lot of servers I would recommend making more Google projects, getting the API keys from those, then using code that will randomly pick from 1 of up to 15 API keys in a text file.
- How can I host this bot without paying?
I would recommend EC2 on AWS for free hosting, you can research how to use that, I am not typing out a tutorial because I am not in the mood to write a 30 page essay.
To reach me if you have any issues, or need help my discord is: Rice#0404.