-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathview.py
More file actions
64 lines (54 loc) · 2.04 KB
/
view.py
File metadata and controls
64 lines (54 loc) · 2.04 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
import discord
class SearchView(discord.ui.View):
def __init__(self, ctx, songs, songReferences, embedBlue, musicQueue):
super().__init__(timeout=60)
self.ctx = ctx
self.songs = songs
self.songReferences = songReferences
self.embedBlue = embedBlue
self.musicQueue = musicQueue
options = [
discord.SelectOption(
label=f"{i+1} - {song['title'][:90]}\n",
value=str(i)
)
for i, song in enumerate(songs)
]
self.select = discord.ui.Select(
placeholder="Select an option",
options=options
)
self.select.callback = self.select_callback
self.add_item(self.select)
cancel_button = discord.ui.Button(
label="Cancel",
style=discord.ButtonStyle.danger
)
cancel_button.callback = self.cancel_callback
self.add_item(cancel_button)
async def select_callback(self, interaction: discord.Interaction):
chosenIndex = int(self.select.values[0])
songRef = self.songReferences[chosenIndex]
embedResponse = discord.Embed(
title=f"Option #{chosenIndex + 1} selected.",
description=f"[{songRef['title']}]({songRef['link']}) added to the queue!",
color=self.embedBlue
)
embedResponse.set_thumbnail(url=songRef['thumbnail'])
self.musicQueue[self.ctx.guild.id].append(
[songRef, self.ctx.author.voice.channel]
)
await interaction.response.edit_message(embed=embedResponse, view=None)
self.stop()
async def cancel_callback(self, interaction: discord.Interaction):
embed = discord.Embed(
title="Search Cancelled",
color=self.embedBlue
)
await interaction.response.edit_message(embed=embed, view=None)
self.stop()
async def on_timeout(self):
try:
await self.message.edit(view=None)
except:
print("Error on_timeout in SearchView.")