Create a Discord Music Bot [Python]

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 พ.ค. 2024
  • Today we'll be making a Discord music bot that plays audio from TH-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

ความคิดเห็น • 71

  • @ethancox2025
    @ethancox2025  2 หลายเดือนก่อน +2

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

    • @Sleepmalice
      @Sleepmalice หลายเดือนก่อน

      Subscribed to you👍

  • @ryanm03
    @ryanm03 หลายเดือนก่อน +1

    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  25 วันที่ผ่านมา

      Much appreciated friend

  • @cauaribeiro2746
    @cauaribeiro2746 2 หลายเดือนก่อน +3

    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  2 หลายเดือนก่อน +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 2 หลายเดือนก่อน +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  2 หลายเดือนก่อน +2

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

  • @alke5789
    @alke5789 หลายเดือนก่อน +1

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

    • @ethancox2025
      @ethancox2025  หลายเดือนก่อน +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!

  • @Phoenix72950
    @Phoenix72950 หลายเดือนก่อน +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  หลายเดือนก่อน +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 หลายเดือนก่อน

      @@ethancox2025 Aye! Okay.

  • @Ksavzx
    @Ksavzx 11 วันที่ผ่านมา

    LoginFailure: Improper token has been passed.

  • @gilwicho3734
    @gilwicho3734 2 หลายเดือนก่อน +3

    Nice Video 10/10

    • @ethancox2025
      @ethancox2025  2 หลายเดือนก่อน

      Glad you found it useful!

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

  • @SaumonArcEnCiel
    @SaumonArcEnCiel หลายเดือนก่อน +1

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

  • @Stationnn
    @Stationnn หลายเดือนก่อน +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  หลายเดือนก่อน

      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!

  • @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  25 วันที่ผ่านมา

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

  • @jefreeyrendon9315
    @jefreeyrendon9315 หลายเดือนก่อน +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  หลายเดือนก่อน

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

    • @jefreeyrendon9315
      @jefreeyrendon9315 หลายเดือนก่อน +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

  • @zacharyRL
    @zacharyRL หลายเดือนก่อน +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  หลายเดือนก่อน

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

  • @nickname7966
    @nickname7966 26 วันที่ผ่านมา

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

  • @xxmoodzz
    @xxmoodzz 13 วันที่ผ่านมา +2

    you are great

    • @ethancox2025
      @ethancox2025  13 วันที่ผ่านมา

      Thank you friend ❤️

  • @izumi6502
    @izumi6502 หลายเดือนก่อน +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

      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.

  • @CarterCovers55
    @CarterCovers55 25 วันที่ผ่านมา

    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  25 วันที่ผ่านมา

      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 25 วันที่ผ่านมา

      @@ethancox2025 cool, can't wait!

  • @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 :)

  • @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 12 วันที่ผ่านมา

    it says expected token is to be in str

  • @flashbang5401
    @flashbang5401 20 วันที่ผ่านมา

    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.

  • @Veteran_47
    @Veteran_47 12 วันที่ผ่านมา +1

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

    • @ethancox2025
      @ethancox2025  12 วันที่ผ่านมา

      Punned comment has a link to a video on fixing that

  • @Creative-Destruction
    @Creative-Destruction 2 หลายเดือนก่อน +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  25 วันที่ผ่านมา

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

  • @smirm6034
    @smirm6034 29 วันที่ผ่านมา

    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 26 วันที่ผ่านมา

      Have you found a solution?

    • @Veteran_47
      @Veteran_47 12 วันที่ผ่านมา

      any solutions ?

  • @s7ksu
    @s7ksu หลายเดือนก่อน +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  หลายเดือนก่อน

      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 หลายเดือนก่อน

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

  • @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: th-cam.com/video/6OrBCaVwjGw/w-d-xo.html

  • @Sleepmalice
    @Sleepmalice หลายเดือนก่อน

    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  หลายเดือนก่อน +1

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

    • @Sleepmalice
      @Sleepmalice หลายเดือนก่อน

      @@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 หลายเดือนก่อน

      @@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: th-cam.com/video/6OrBCaVwjGw/w-d-xo.html

  • @JhonDaid_JD
    @JhonDaid_JD 27 วันที่ผ่านมา

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

  • @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! th-cam.com/video/6OrBCaVwjGw/w-d-xo.html