Horje
discord music queue python Code Example
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')




Python

Related
sort dictionary python Code Example sort dictionary python Code Example
start new app in django Code Example start new app in django Code Example
time date in pandas to csv file Code Example time date in pandas to csv file Code Example
url in form action django Code Example url in form action django Code Example
check palindrome in python using recursion Code Example check palindrome in python using recursion Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7