Create a Discord Music Bot with a Queue in Python [2024]
Published 2024-04-13
*DISCLAIMER*
This video is for educational purposes ONLY. Anything produced by this video should respect YouTube guidelines on streaming and downloading videos. Bots made using this content are not to be distributed, both non-commercially and commercially.
Old bot code: github.com/MasterReach1/discord-bots/tree/main/Mus…
Code for this video:
github.com/MasterReach1/discord-bots/tree/main/Mus…
Timeline:
00:00 Intro
00:18 Web portal settings
02:50 Get base code
03:24 Setting up prefix (slash) commands
05:54 Make queue command
07:54 Add play next song function to play()
09:43 After function of play()
10:08 Lambda function explained
11:24 Testing the queue
12:38 Add memory safe feature to stop()
13:08 Clear queue function
15:00 Test clear queue function
15:51 Outro
All Comments (19)
-
#skip voice_clients[msg.guild.id].stop() await play_next(ctx)
-
Too late to reply.. But greatt tutorial everything worked smoothly as per the need.. Future potential tutorial idea: searching for URL if name of the video is provided.
-
Thanks my dude!
-
very useful,thanks for the perfect tutorial.
-
Thank you! queue for this case is really not so obvious as i thinked.If we want to repeat our queue for playing maybe realise linkedlist?
-
#repeat @client.command(name = "repeat") async def repeat(ctx): global repeat_songs global current_song repeat_songs = abs(repeat_songs-1) if repeat_songs == 1: await queue(ctx,current_song) await ctx.send("repeated now") else: await ctx.send("don't repeated now") idk how to avoid in python keyword "global" for global vars in this context, but it works.var current_song is the current played song.In the play_next popping url adding to queue again and so on Also repeat_songs must be boolean type this my mistake/
-
Hi, there's a problem. I did everything as shown in the video, but at startup it gives the following error Traceback (most recent call last): File "c:\ds_bot\main.py", line 4, in <module> bot.run_bot() File "c:\ds_bot\bot.py", line 107, in run_bot client.run(TOKEN) File "C:\Users\OLEG\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 860, in run asyncio.run(runner()) File "C:\Users\OLEG\AppData\Local\Programs\Python\Python39\lib\asyncio\runners.py", line 44, in run return loop.run_until_complete(main) File "C:\Users\OLEG\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 642, in run_until_complete return future.result() File "C:\Users\OLEG\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 849, in runner await self.start(token, reconnect=reconnect) File "C:\Users\OLEG\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 777, in start await self.login(token) File "C:\Users\OLEG\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 609, in login raise TypeError(f'expected token to be a str, received {token.__class__.__name__} instead') TypeError: expected token to be a str, received NoneType instead Could you help me figure this out?
-
ty 🖤
-
Gonna try an make this tomorrow
-
It doesn't play for me. I get this error: ffmpeg was not found... [youtube] Extracting URL: https://www.youtube.com/watch?v=tzfVd_xq80k [youtube] tzfVd_xq80k: Downloading webpage [youtube] tzfVd_xq80k: Downloading ios player API JSON [youtube] tzfVd_xq80k: Downloading m3u8 information ffmpeg was not found. What could be wrong?
-
Hi there! Quick question here, I'm trying to have my bot play webradio but to save on bandwith I disconnect the stream. is it normat that voiceclient.is_playing still returns true after running voice_client.stop() ? I tried to check this to prevent the 'is already playing audio' error on reconnecting when someone joins the channel.
-
Can someone explain to me why when I add a track to the queue, the playing music starts to freeze?
-
Thank for vid. What about video how upload bot on hosting service? It will help a lot
-
Hello 👋🏿 i need help
-
does this support playing playlists?
-
git pull?
-
Hy there Ethan thanks for this informing video i'm having trouble on this and i try adding it as a cog rather than a async function it still runs but it's giving me the error of ffmpeg not found even i did add it to my enviroments variables : Already connected to a voice channel. [youtube] Extracting URL: www.youtube.com/watch?v=n78m4NjhqGg&t=717s&… [youtube] tS8nzAQg_8k: Downloading webpage [youtube] tS8nzAQg_8k: Downloading ios player API JSON [youtube] tS8nzAQg_8k: Downloading android player API JSON [youtube] tS8nzAQg_8k: Downloading m3u8 information ffmpeg was not found.
-
ty Ethan :face-red-heart-shape: