Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

discord music queue python

import discord
from discord.ext import commands
import os
import bunchi_commands
import youtube_dl

#intents
intents = discord.Intents.default()
intents.members = True
intents.presences = True

#variabeln
queue = []


#implementation
class MyClient(discord.Client):
    #-------------------------------------------------
    async def on_message(self, message): 
        prefix = "~"
        if message.author != self.user:
            msg = message.content.split()

            voicechannel = message.author.voice.channel
            voiceclient = message.guild.voice_client

        #-------------(voice-commands)--------------------
            elif msg[0] == prefix+"join":
                if voiceclient and voiceclient.is_connected():
                    await voiceclient.move_to(voicechannel)
                else:
                    await voicechannel.connect()

            elif msg[0] == prefix+"dc":         
                if voiceclient.is_connected():
                    await voiceclient.disconnect()

            elif msg[0] == prefix+"play":
                if voiceclient and voiceclient.is_connected():      # just connecting to the voicechannel and voiceclient
                    await voiceclient.move_to(voicechannel)         # 
                else:                                               #  
                    await voicechannel.connect()                    # 

                
                url = str(message.content)[len(msg[0])+1:]          
                dirpath = './downloadsong'                          
                filename = 'song.mp3'                           
                filepath = '{}/{}'.format(dirpath,filename)

                if queue == []:                                      # if queue is empty (=not playing a song right now)
                    bunchi_commands.check_song(filepath)                # delete old song
                    bunchi_commands.download_song(url,filepath)         # download new song

                    voiceclient.play(discord.FFmpegPCMAudio("./downloadsong/song.mp3")) # play song

                bunchi_commands.addqueue(queue,url)
                print(queue)
                            
            elif msg[0] == prefix+"pause":
                if voiceclient.is_playing():
                    voiceclient.pause()

            elif msg[0] == prefix+"resume":
                if voiceclient.is_paused():
                    voiceclient.resume()
            
            elif msg[0] == prefix+"stop":
                voiceclient.stop()

    
#---------------------------------------------------
client = MyClient(intents=intents)
client.run('Token')
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #discord #music #queue #python
ADD COMMENT
Topic
Name
3+9 =