-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdropdown.py
More file actions
66 lines (52 loc) · 2.34 KB
/
dropdown.py
File metadata and controls
66 lines (52 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import discord.ui
from discord import FFmpegPCMAudio
import bot
def check_queue(ctx):
if not bot.queue.is_empty():
voice = ctx.guild.voice_client
source = bot.queue.get_next_track()
voice.play(source, after=lambda x: check_queue(ctx))
class SongDropdown(discord.ui.Select):
def __init__(self, options, ctx):
# options=[
# discord.SelectOption(label="A", description="SSS"),
# discord.SelectOption(label="AA", description="SSS"),
# discord.SelectOption(label="AAA", description="SSS")
# ]
# self.c = ctx
# self.options = option
self.paths = dict()
self.ctx = ctx
selects = []
songs = []
for i in range(len(options)):
song = options[i][1]
path = options[i][0] + "/" + song
self.paths[song] = path
item_label = f"{i + 1} : " + song
songs.append(item_label)
select_option = discord.SelectOption(label=item_label, description=song)
selects.append(select_option)
self.list_songs = '\n'.join(songs)
super().__init__(placeholder="Here are the related Songs!", options=selects, min_values=1, max_values=1)
async def callback(self,
interaction: discord.Interaction): # the function called when the user is done selecting options
song_name = self.values[0][4:]
await interaction.response.send_message(f"{song_name} has been added!", delete_after=10)
path = self.paths[song_name]
source = FFmpegPCMAudio(executable='C:/Users/User/FFMPEG/ffmpeg.exe',
source=path)
bot.queue.add(song_name, source)
voice = self.ctx.guild.voice_client
if not self.ctx.guild.voice_client.is_playing() and bot.queue.get_position() == 0:
bot.queue.increase_position()
player = voice.play(source, after=lambda x: check_queue(self.ctx))
# source = FFmpegPCMAudio(executable='C:/Users/User/FFMPEG/ffmpeg.exe',
# source=path)
# player = self.ctx.voice_client.play(source)-tes
class MyView(discord.ui.View):
def __init__(self, options, ctx):
dropdown = SongDropdown(options, ctx)
self.list_songs = dropdown.list_songs
super().__init__()
self.add_item(dropdown)