1import discord
2from discord.ext import commands
3import os
4import bunchi_commands
5import youtube_dl
6
7#intents
8intents = discord.Intents.default()
9intents.members = True
10intents.presences = True
11
12#variabeln
13queue = []
14
15
16#implementation
17class MyClient(discord.Client):
18 #-------------------------------------------------
19 async def on_message(self, message):
20 prefix = "~"
21 if message.author != self.user:
22 msg = message.content.split()
23
24 voicechannel = message.author.voice.channel
25 voiceclient = message.guild.voice_client
26
27 #-------------(voice-commands)--------------------
28 elif msg[0] == prefix+"join":
29 if voiceclient and voiceclient.is_connected():
30 await voiceclient.move_to(voicechannel)
31 else:
32 await voicechannel.connect()
33
34 elif msg[0] == prefix+"dc":
35 if voiceclient.is_connected():
36 await voiceclient.disconnect()
37
38 elif msg[0] == prefix+"play":
39 if voiceclient and voiceclient.is_connected(): # just connecting to the voicechannel and voiceclient
40 await voiceclient.move_to(voicechannel) #
41 else: #
42 await voicechannel.connect() #
43
44
45 url = str(message.content)[len(msg[0])+1:]
46 dirpath = './downloadsong'
47 filename = 'song.mp3'
48 filepath = '{}/{}'.format(dirpath,filename)
49
50 if queue == []: # if queue is empty (=not playing a song right now)
51 bunchi_commands.check_song(filepath) # delete old song
52 bunchi_commands.download_song(url,filepath) # download new song
53
54 voiceclient.play(discord.FFmpegPCMAudio("./downloadsong/song.mp3")) # play song
55
56 bunchi_commands.addqueue(queue,url)
57 print(queue)
58
59 elif msg[0] == prefix+"pause":
60 if voiceclient.is_playing():
61 voiceclient.pause()
62
63 elif msg[0] == prefix+"resume":
64 if voiceclient.is_paused():
65 voiceclient.resume()
66
67 elif msg[0] == prefix+"stop":
68 voiceclient.stop()
69
70
71#---------------------------------------------------
72client = MyClient(intents=intents)
73client.run('Token')
74