Create a Discord Music Bot [Python]

Поділитися
Вставка
  • Опубліковано 13 чер 2024
  • Today we'll be making a Discord music bot that plays audio from UA-cam 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

КОМЕНТАРІ • 78

  • @ethancox2025
    @ethancox2025  2 місяці тому +3

    If you are running into the issue: "ffmpeg process [x] successfully terminated with return code of 0", then watch this video for the fix: ua-cam.com/video/6OrBCaVwjGw/v-deo.html

  • @ryanm03
    @ryanm03 Місяць тому +2

    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!

  • @cauaribeiro2746
    @cauaribeiro2746 3 місяці тому +4

    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  3 місяці тому +1

      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

  • @aaroncraig-kg5wx
    @aaroncraig-kg5wx 3 місяці тому +7

    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  3 місяці тому +2

      Thank you for pointing these out and listing them here! I'm glad you found the video valuable

  • @alke5789
    @alke5789 2 місяці тому +1

    Nice video, man.
    it would be nice if you make a video implementing a music queue.

    • @ethancox2025
      @ethancox2025  2 місяці тому +1

      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!

  • @CarterCovers55
    @CarterCovers55 Місяць тому

    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  Місяць тому

      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 Місяць тому

      @@ethancox2025 cool, can't wait!

  • @gilwicho3734
    @gilwicho3734 3 місяці тому +3

    Nice Video 10/10

  • @Phoenix72950
    @Phoenix72950 2 місяці тому +2

    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  2 місяці тому +1

      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 2 місяці тому

      @@ethancox2025 Aye! Okay.

  • @jguivianna-4982
    @jguivianna-4982 Місяць тому +1

    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

  • @BEZERKER45
    @BEZERKER45 2 місяці тому +1

    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  Місяць тому

      Absolutely! You can add whatever functions you want, it's a standard Discord bot

  • @SaumonArcEnCiel
    @SaumonArcEnCiel Місяць тому +1

    Hi, thanks but I have this error :
    AttributeError: 'FFmpegOpusAudio' object has no attribute '_process'

  • @slavic_fox98
    @slavic_fox98 13 днів тому +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  12 днів тому

      Is there anything in the output window?

  • @zacharyRL
    @zacharyRL 2 місяці тому +1

    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  2 місяці тому

      This is one of my earlier videos using ChatGPT. I also have one building a dialogue bot with ChatGPT and Discord!
      ua-cam.com/video/r_DniRY9edY/v-deo.htmlsi=JDtADbpDSPzoKA9t

  • @nickname7966
    @nickname7966 Місяць тому

    How can i add a skip button? For example i have two songs in the queue and i want to skip the first one

  • @Stationnn
    @Stationnn 2 місяці тому +2

    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  2 місяці тому

      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!

  • @xxmoodzz
    @xxmoodzz 29 днів тому +2

    you are great

  • @izumi6502
    @izumi6502 2 місяці тому +2

    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  2 місяці тому +2

      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.

  • @josephsalazar6096
    @josephsalazar6096 6 днів тому +1

    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  6 днів тому

      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

  • @Creative-Destruction
    @Creative-Destruction 3 місяці тому +2

    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  Місяць тому

      Spotify isn't a free option, but I just dropped a video on searching music via keyword on UA-cam. Check it out if you want!

  • @Veteran_47
    @Veteran_47 28 днів тому +1

    ffmpeg process 9732 should have terminated with a return code of 1.
    any fix ?

    • @ethancox2025
      @ethancox2025  28 днів тому

      Punned comment has a link to a video on fixing that

  • @WWickenden
    @WWickenden Місяць тому +1

    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 Місяць тому +2

      Nvm I fixed it. I just had to put ffmpeg.exe into the bot folder. All the best :)

  • @jefreeyrendon9315
    @jefreeyrendon9315 2 місяці тому +2

    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  2 місяці тому

      You need to run the bot from VS Code before it will come online

    • @jefreeyrendon9315
      @jefreeyrendon9315 2 місяці тому +1

      @@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

  • @felipedemarchi8927
    @felipedemarchi8927 Місяць тому +1

    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  Місяць тому

      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

  • @Veteran_47
    @Veteran_47 28 днів тому

    it says expected token is to be in str

  • @s7ksu
    @s7ksu 2 місяці тому +1

    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  2 місяці тому

      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 2 місяці тому

      @@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?

  • @victoriachoi6963
    @victoriachoi6963 7 днів тому +1

    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  7 днів тому

      Try the solution in the pinned comment's video. That fixed it for a few people

    • @victoriachoi6963
      @victoriachoi6963 7 днів тому

      @@ethancox2025 it worked thank you!

  • @apotato2855
    @apotato2855 2 місяці тому +1

    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  2 місяці тому +1

      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 2 місяці тому

      @@ethancox2025 Thanks, u have helped me a lot with your video!!

    • @apotato2855
      @apotato2855 2 місяці тому +1

      @@ethancox2025 Do you know why the bot stops playing after a certain amount of time? it doesnt play the whole song.

    • @ethancox2025
      @ethancox2025  2 місяці тому

      @@apotato2855 Does it say "ffmpeg process x successfully terminated with a return code of 0"?
      If so, do this: ua-cam.com/video/6OrBCaVwjGw/v-deo.html

  • @Ksavzx
    @Ksavzx 27 днів тому

    LoginFailure: Improper token has been passed.

  • @JhonDaid_JD
    @JhonDaid_JD Місяць тому

    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")

  • @smirm6034
    @smirm6034 Місяць тому

    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

  • @Sleepmalice
    @Sleepmalice 2 місяці тому

    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  2 місяці тому +1

      Be sure you add the Message Intent in the Developer Web Console

    • @Sleepmalice
      @Sleepmalice 2 місяці тому

      @@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 2 місяці тому

      @@ethancox2025 yes! it works.Also I imported nacl library

  • @its_fog
    @its_fog 2 місяці тому +2

    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  2 місяці тому

      Apologies for the delayed response, friend. Here's a short video on fixing this: ua-cam.com/video/6OrBCaVwjGw/v-deo.html

  • @flashbang5401
    @flashbang5401 Місяць тому

    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 2 місяці тому +1

    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  2 місяці тому

      I have made a short video addressing this issue since it's pretty common for all who have completed this tutorial. Hope it helps! ua-cam.com/video/6OrBCaVwjGw/v-deo.html