Search
 
SCRIPT & CODE EXAMPLE
 

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')
Comment

PREVIOUS NEXT
Code Example
Python :: how to print sum of two numbers in python 
Python :: python take the month of date in new column 
Python :: how to detect language python 
Python :: make averages on python 
Python :: python size of linked list 
Python :: python string match ignore case 
Python :: how to import a python function from another file 
Python :: ImportError: No module named flask 
Python :: pandas multiindex to single index 
Python :: Django group by date from datetime field 
Python :: how to use dictionary comprehension to make a dictionary for some names of a list in python 
Python :: python make sound when finished 
Python :: show integer seabron heatmap values 
Python :: what is the use of class in python 
Python :: how to import date python 
Python :: install virtual environment python mac 
Python :: set title matplotlib 
Python :: load a Dictionary from File in Python Using the Load Function of the pickle Module 
Python :: renaming column in dataframe pandas 
Python :: django permission required 
Python :: how to sort tuples in list python 
Python :: Python program to check Co-Prime Number 
Python :: inline if python 
Python :: internal server error 500 python flask 
Python :: delete spaces in string python 
Python :: python print boolean 
Python :: choromap = go.Figure(data=[data], layout = layout) 
Python :: if found then stop the loop python 
Python :: remove first character from string python 
Python :: Replace the string with NAN value 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =