Create a Discord Music Bot [Python]
2024 ж. 23 Мам.
6 223 Рет қаралды
Today we'll be making a Discord music bot that plays audio from KZhead videos! It's a long ride to get this going, so be sure to grab a coffee and strap in for this video.
FFmpeg download: www.gyan.dev/ffmpeg/builds/
GitHub files: github.com/MasterReach1/disco...
Timeline:
00:00 Building the bot on Discord
01:46 Setting up for the code
02:05 Downloading FFmpeg
02:30 Setting FFmpeg path as environment variable
03:39 Install required packages
04:50 Set up run_bot()
04:54 Load .env variables
05:12 Discussing .env
06:45 Setting up variables
08:44 Setting up on_ready()
09:00 Setting up on_message()
09:15 Setting up ?play command
13:12 First error
13:42 First successful test
14:15 Adding ?pause command and others
15:30 Second successful test
15:55 Outro
If you are running into the issue: "ffmpeg process [x] successfully terminated with return code of 0", then watch this video for the fix: kzhead.info/sun/abOrcqeZjamgeq8/bejne.html
Subscribed to you👍
Man, you really saved me with this tutorial! You explain everything very well. Apparently, the only error I had was that I needed to install "pip install PyNaCl". Other than that, everything worked perfectly. Thank you for the video! I'm Brazilian and I loved your video. I hope you have more success!
I'm so glad you found it helpful! Thanks for letting me know about the extra streaming package requirement; anyone who faces the same issue will see this comment. Much love, dude
great tutorial! thanks for giving me the foundation of my own bot. Also you are a pretty funny guy lol made the video even better with your personality. keep it up!
Much appreciated friend
Nice video, man. it would be nice if you make a video implementing a music queue.
Yessir! I've had this request so much, I'm dropping the video on that this week. Be sure to check back or just turn notifications on!
Nice Video 10/10
Glad you found it useful!
Thank you so much! I was having some trouble with some stuff and you helped a lot! Ah, I wanted to add some slash commands. But it was pretty hard to sync with discord. Do you perhaps have a video about it? Anyway, thanks a lot!
I have a video on making a slash command bot out now, but this week I'm dropping a music bot tutorial that uses prefix commands and has a queue!
@@ethancox2025 Aye! Okay.
Excellent stuff. I ran into 2 errors, which I can see others hitting as well. 1) My path environment didn't want to update until I restarted my computer. I'm on Windows. 2) I needed to install the library pynacl, as my bot couldn't join the voice channel and ffmepg was stalling out.
Thank you for pointing these out and listing them here! I'm glad you found the video valuable
you are great
Thank you friend ❤️
This is one of the two bots I have been trying to research making. I saw you are going to make an updated version of this with a queue and slash command so I look forward to that, is there anyway you can make a video about a chatgpt bot? Every video I find in python is outdated and doesn't work. Thanks!
This is one of my earlier videos using ChatGPT. I also have one building a dialogue bot with ChatGPT and Discord! kzhead.info/sun/pcN9ns2KkGubl5E/bejne.htmlsi=JDtADbpDSPzoKA9t
thank you so much bro! I was struggling to set one up. tell me something, can I join other functions like messages to the bot or not?
Absolutely! You can add whatever functions you want, it's a standard Discord bot
Im having a problem with yt_dlp, the import command isn't recognizing it. The error is: "reportMissingImports" And I already downloaded yt_dlp but it still doesn't work
LoginFailure: Improper token has been passed.
Hi, thanks but I have this error : AttributeError: 'FFmpegOpusAudio' object has no attribute '_process'
Thank you so much on the tutorial! I successfully created my bot. However, I want this bot to be able to add a song in the queue when I use ?play twice or more, and it will automatically play the next song. Can you advice me on how to do this? Even better if you make a tutorial about that.
I'm glad you found this helpful! Also, yes I will be making a tutorial on a modern music bot using slash commands, and the queue will be included there.
Thanks for this, was able to resurrect my long dead music bot after youtube_dl ceased being maintained. However I noticed when testing this the TLS session could be come dead "for some reason" according to error logs...is there a way to fully download the audio source before it plays to avoid this issue? I'm doing research on my own just not sure if you ran into this or not.
I'm actually looking to into caching the song as it plays + the queue as the network allows. Kind of like how a standard music streaming app works. It'll be a future video!
@@ethancox2025 cool, can't wait!
How can i add a skip button? For example i have two songs in the queue and i want to skip the first one
would you mind adding on a section where you can add songs to a queue and loop a specific song? if making a video is too difficult or time consuming, i would appreciate the sections of code alone in the comments and i can add them to my files myself, thanks!
No worries man! I've got a video on queues dropping this week. Just had a tight schedule lately and finally have time again for videos.
@@ethancox2025 thats great to hear! thanks for the heads up, is there a date i should be looking forward to or just this week in general?
Hello, thank u so much for this tutorial but i have a problem : My bot doesn’t come in the voice channel, do you know why ? ( btw there is no error message in the terminal)
Make sure you're in the voice channel that you want him in. Also make sure to give him Guild and Message intents in the Developer console on the web!
Hey awsome video, I'm getting an issue where whenever I play I get the issue in the terminal "ffmpeg was not found"
Nvm I fixed it. I just had to put ffmpeg.exe into the bot folder. All the best :)
Good video. I have an issue that everytime i try to play a youtube video i get the error "ERROR: [youtube] hhfzhvurx7k: Video unavailable". Is there a fix for that?
Some videos might have restrictions on using a third party to play the video. This video is simply for entertainment and educational purposes, so you'll need to just use discretion in selecting a video
ffmpeg process 9732 should have terminated with a return code of 1. any fix ?
Punned comment has a link to a video on fixing that
Bro can u please create a tutorial on a music bot which searches music from the given text on spotify and other platforms. (Please create the text one so that people can use the music bot easily please bro)
Spotify isn't a free option, but I just dropped a video on searching music via keyword on KZhead. Check it out if you want!
Hello friend, sorry, I'm new to programming. I have a problem: I can't get my bot online. What can I do?
You need to run the bot from VS Code before it will come online
@@ethancox2025 I followed the tutorial to the letter, but simply when I run the code in vscode the bot does not start, nor do I know where you put the bot token Excuse me for the trouble
it says expected token is to be in str
I'm having trouble with the code, especially with ffmpeg. Everything else is working fine, but when I try to play a song, it keeps saying "ffmpeg not found."
Once ffmpeg has been installed and added to your system path variable, you might need to reboot your computer in order for the changes to take effect. Let me know if that helps!
@@ethancox2025 Thanks, u have helped me a lot with your video!!
@@ethancox2025 Do you know why the bot stops playing after a certain amount of time? it doesnt play the whole song.
@@apotato2855 Does it say "ffmpeg process x successfully terminated with a return code of 0"? If so, do this: kzhead.info/sun/abOrcqeZjamgeq8/bejne.html
Hi, thanks for the tutorial, but there is a question every time, regardless of the device, ffmpeg returns error code 1 to me, everything is installed and global variables are set, I don't know what to do, don't you know how to fix it? I can't find a solution to the problem on stackoverflow and github For example: 2024-05-08 09:50:20 INFO discord.player ffmpeg process 3544 has not terminated. Waiting to terminate... 2024-05-08 09:50:20 INFO discord.player ffmpeg process 3544 should have terminated with a return code of 1.
Thank you so mush for this tutorial! I have issue that bot don't get messages from channel only if send direct message
Be sure you add the Message Intent in the Developer Web Console
@@ethancox2025 thank you! but now i have another issue - when the message event triggered in the message object has no attribute autor but in debug mode this exists.So strange upd: sorry this my mistake autor instead author
@@ethancox2025 yes! it works.Also I imported nacl library
Hello guys. Thank you for a great tutorial, but I'm facing a problem with ffmpeg not terminating ffmpeg process 18188 has not terminated. Waiting to terminate... ffmpeg process 18188 should have terminated with a return code of 1. Tried different things, don't know what to do
Have you found a solution?
any solutions ?
Im having this weird problem (not an error exactly). So whenever I play a music by bot loves to stops it in the middle and gives an error like: ffmpeg process 13268 successfully terminated with a return code of 0. Can anyone point out the reason?
Apologies for the delayed response, friend. Here's a short video on fixing this: kzhead.info/sun/abOrcqeZjamgeq8/bejne.html
In this piece of code you can see that I don't have any errors, but my bot still joins the voice channel but I don't hear it, what could it be? @client.event async def on_message(msg): if msg.content.startswith("?play"): try: voice_client = await msg.author.voice.channel.connect() voice_clients[voice_clients.guild.id] = voice_client except Exception as e: print("error")
Im having this issue where the bot randomly stops playing. Do you know how i fix this? "discord.player ffmpeg process 3000 successfully terminated with return code of 0." (the number changes every time)
I have made a short video addressing this issue since it's pretty common for all who have completed this tutorial. Hope it helps! kzhead.info/sun/abOrcqeZjamgeq8/bejne.html