Create a Discord Music Bot [Python]

  Рет қаралды 10,099

Ethan | The Code Syndicate

Ethan | The Code Syndicate

Күн бұрын

Today we'll be making a Discord music bot that plays audio from KZfaq videos! It's a long ride to get this going, so be sure to grab a coffee and strap in for this video.
*DISCLAIMER*
This video is for educational purposes ONLY. Anything produced by this video should respect KZfaq guidelines on streaming and downloading videos. Bots made using this content are not to be distributed, both non-commercially and commercially.
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

Пікірлер: 81
@ethancox2025
@ethancox2025 4 ай бұрын
If you are running into the issue: "ffmpeg process [x] successfully terminated with return code of 0", then watch this video for the fix: kzfaq.info/get/bejne/bLWidaaSu93Od6s.html
@Sleepmalice
@Sleepmalice 3 ай бұрын
Subscribed to you👍
@cauaribeiro2746
@cauaribeiro2746 5 ай бұрын
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!
@ethancox2025
@ethancox2025 5 ай бұрын
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
@ryanm03
@ryanm03 3 ай бұрын
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!
@ethancox2025
@ethancox2025 2 ай бұрын
Much appreciated friend
@Samuel-pc8zv
@Samuel-pc8zv 7 күн бұрын
Great video, good and simple explanation. congrats!
@ethancox2025
@ethancox2025 7 күн бұрын
@@Samuel-pc8zv thank you!
@alke5789
@alke5789 3 ай бұрын
Nice video, man. it would be nice if you make a video implementing a music queue.
@ethancox2025
@ethancox2025 3 ай бұрын
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!
@gilwicho3734
@gilwicho3734 4 ай бұрын
Nice Video 10/10
@ethancox2025
@ethancox2025 4 ай бұрын
Glad you found it useful!
@Ksavzx
@Ksavzx 2 ай бұрын
LoginFailure: Improper token has been passed.
@aaroncraig-kg5wx
@aaroncraig-kg5wx 4 ай бұрын
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.
@ethancox2025
@ethancox2025 4 ай бұрын
Thank you for pointing these out and listing them here! I'm glad you found the video valuable
@jguivianna-4982
@jguivianna-4982 3 ай бұрын
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
@xxmoodzz
@xxmoodzz 2 ай бұрын
you are great
@ethancox2025
@ethancox2025 2 ай бұрын
Thank you friend ❤️
@TheFrenchSalmon
@TheFrenchSalmon 3 ай бұрын
Hi, thanks but I have this error : AttributeError: 'FFmpegOpusAudio' object has no attribute '_process'
@nickname7966
@nickname7966 3 ай бұрын
How can i add a skip button? For example i have two songs in the queue and i want to skip the first one
@Phoenix72950
@Phoenix72950 3 ай бұрын
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!
@ethancox2025
@ethancox2025 3 ай бұрын
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!
@Phoenix72950
@Phoenix72950 3 ай бұрын
@@ethancox2025 Aye! Okay.
@BEZERKER45
@BEZERKER45 4 ай бұрын
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?
@ethancox2025
@ethancox2025 2 ай бұрын
Absolutely! You can add whatever functions you want, it's a standard Discord bot
@zacharyRL
@zacharyRL 3 ай бұрын
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!
@ethancox2025
@ethancox2025 3 ай бұрын
This is one of my earlier videos using ChatGPT. I also have one building a dialogue bot with ChatGPT and Discord! kzfaq.info/get/bejne/qMV0ocyDvp_JlI0.htmlsi=JDtADbpDSPzoKA9t
@Stationnn
@Stationnn 3 ай бұрын
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)
@ethancox2025
@ethancox2025 3 ай бұрын
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!
@Veteran_47
@Veteran_47 2 ай бұрын
it says expected token is to be in str
@josephsalazar6096
@josephsalazar6096 Ай бұрын
Am I just bad at following a tutorial or what? I get to the part at install packages and my terminal (using Pycharm) then says this error pip : The term 'pip' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + pip install --asyncio + ~~~ + CategoryInfo : ObjectNotFound: (pip:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException What do I even do??
@ethancox2025
@ethancox2025 Ай бұрын
No sir, you're not bad at all. There are a few options in this scenario. The problem is either you don't have pip installed, which I assume you do, or your pycharm doesn't recognize pip. If you don't have pip, go ahead and look into getting it installed. It's really fast and easy. If you do, my visual studio does this at work but not at home, so I have a solution. Use the command prompt / terminal to navigate to your project directory and run pip there. If that doesn't work, run "python -m pip {command-here}" IF NONE OF THIS WORKS: try "pip3 install {package-name}" in either terminal
@izumi6502
@izumi6502 4 ай бұрын
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.
@ethancox2025
@ethancox2025 4 ай бұрын
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.
@Creative-Destruction
@Creative-Destruction 4 ай бұрын
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)
@ethancox2025
@ethancox2025 2 ай бұрын
Spotify isn't a free option, but I just dropped a video on searching music via keyword on KZfaq. Check it out if you want!
@CarterCovers55
@CarterCovers55 2 ай бұрын
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.
@ethancox2025
@ethancox2025 2 ай бұрын
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!
@CarterCovers55
@CarterCovers55 2 ай бұрын
@@ethancox2025 cool, can't wait!
@jefreeyrendon9315
@jefreeyrendon9315 3 ай бұрын
Hello friend, sorry, I'm new to programming. I have a problem: I can't get my bot online. What can I do?
@ethancox2025
@ethancox2025 3 ай бұрын
You need to run the bot from VS Code before it will come online
@jefreeyrendon9315
@jefreeyrendon9315 3 ай бұрын
@@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
@slavic_fox98
@slavic_fox98 2 ай бұрын
Everythings works except for when the bot joins the channel no music is played... what could be causing this issue? Thank you for this tutorial btw
@ethancox2025
@ethancox2025 2 ай бұрын
Is there anything in the output window?
@WWickenden
@WWickenden 3 ай бұрын
Hey awsome video, I'm getting an issue where whenever I play I get the issue in the terminal "ffmpeg was not found"
@WWickenden
@WWickenden 3 ай бұрын
Nvm I fixed it. I just had to put ffmpeg.exe into the bot folder. All the best :)
@victoriachoi6963
@victoriachoi6963 Ай бұрын
keep getting the errors: ffmpeg process 10260 has not terminated. Waiting to terminate... ffmpeg process 10260 should have terminated with a return code of -9. how do i fix this?
@ethancox2025
@ethancox2025 Ай бұрын
Try the solution in the pinned comment's video. That fixed it for a few people
@victoriachoi6963
@victoriachoi6963 Ай бұрын
@@ethancox2025 it worked thank you!
@felipedemarchi8927
@felipedemarchi8927 3 ай бұрын
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?
@ethancox2025
@ethancox2025 3 ай бұрын
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
@JhonDaid_JD
@JhonDaid_JD 3 ай бұрын
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")
@Veteran_47
@Veteran_47 2 ай бұрын
ffmpeg process 9732 should have terminated with a return code of 1. any fix ?
@ethancox2025
@ethancox2025 2 ай бұрын
Punned comment has a link to a video on fixing that
@apotato2855
@apotato2855 4 ай бұрын
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."
@ethancox2025
@ethancox2025 4 ай бұрын
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!
@apotato2855
@apotato2855 4 ай бұрын
@@ethancox2025 Thanks, u have helped me a lot with your video!!
@apotato2855
@apotato2855 4 ай бұрын
@@ethancox2025 Do you know why the bot stops playing after a certain amount of time? it doesnt play the whole song.
@ethancox2025
@ethancox2025 4 ай бұрын
@@apotato2855 Does it say "ffmpeg process x successfully terminated with a return code of 0"? If so, do this: kzfaq.info/get/bejne/bLWidaaSu93Od6s.html
@s7ksu
@s7ksu 3 ай бұрын
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!
@ethancox2025
@ethancox2025 3 ай бұрын
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.
@s7ksu
@s7ksu 3 ай бұрын
@@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?
@Sleepmalice
@Sleepmalice 3 ай бұрын
Thank you so mush for this tutorial! I have issue that bot don't get messages from channel only if send direct message
@ethancox2025
@ethancox2025 3 ай бұрын
Be sure you add the Message Intent in the Developer Web Console
@Sleepmalice
@Sleepmalice 3 ай бұрын
@@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
@Sleepmalice
@Sleepmalice 3 ай бұрын
@@ethancox2025 yes! it works.Also I imported nacl library
@smirm6034
@smirm6034 3 ай бұрын
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
@fletline7326
@fletline7326 3 ай бұрын
Have you found a solution?
@Veteran_47
@Veteran_47 2 ай бұрын
any solutions ?
@its_fog
@its_fog 4 ай бұрын
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?
@ethancox2025
@ethancox2025 4 ай бұрын
Apologies for the delayed response, friend. Here's a short video on fixing this: kzfaq.info/get/bejne/bLWidaaSu93Od6s.html
@flashbang5401
@flashbang5401 2 ай бұрын
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.
@MaxOppendijk
@MaxOppendijk 4 ай бұрын
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)
@ethancox2025
@ethancox2025 4 ай бұрын
I have made a short video addressing this issue since it's pretty common for all who have completed this tutorial. Hope it helps! kzfaq.info/get/bejne/bLWidaaSu93Od6s.html
Python Project: Discord Music Bot In 50 Lines
5:44
Max Codez
Рет қаралды 3,1 М.
Summer shower by Secret Vlog
00:17
Secret Vlog
Рет қаралды 12 МЛН
Clowns abuse children#Short #Officer Rabbit #angel
00:51
兔子警官
Рет қаралды 79 МЛН
EVOLUTION OF ICE CREAM 😱 #shorts
00:11
Savage Vlogs
Рет қаралды 8 МЛН
Gym belt !! 😂😂  @kauermtt
00:10
Tibo InShape
Рет қаралды 17 МЛН
These People Need To STOP...
8:09
Reddest Engineer
Рет қаралды 979
I run untested, viewer-submitted code on my 500-LED christmas tree.
45:17
Why You Shouldn't Nest Your Code
8:30
CodeAesthetic
Рет қаралды 2,6 МЛН
Create a Discord Music Bot with a Queue in Python [2024]
17:33
Ethan | The Code Syndicate
Рет қаралды 4,2 М.
EASY! Organize Your Messy Code Using COGS! (Ep. 13)
16:36
sanamo
Рет қаралды 13 М.
Cracking Software with Reverse Engineering 😳
8:01
nang
Рет қаралды 1,6 МЛН
You Might Lose your Active Developer Badge!
10:49
No Text To Speech
Рет қаралды 522 М.
Code Your Own Discord Bot - Basics (2024)
11:40
Golden Development
Рет қаралды 19 М.
3 PYTHON AUTOMATION PROJECTS FOR BEGINNERS
17:00
Internet Made Coder
Рет қаралды 1,6 МЛН
Make Your Own Advanced Discord Music Bot🎵 NOW!! 🔥(2024)
4:12
Summer shower by Secret Vlog
00:17
Secret Vlog
Рет қаралды 12 МЛН