-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomponents.py
More file actions
90 lines (71 loc) · 2.97 KB
/
components.py
File metadata and controls
90 lines (71 loc) · 2.97 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# make examples for buttons, feedback (modals) and other stuff
# https://www.youtube.com/watch?v=dxcSt9Ip63w
import discord
from discord import app_commands
class SimpleView(discord.ui.View):
async def disable_all_items(self):
for item in self.children:
item.disabled = True
await self.message.edit(view=self)
async def on_timeout(self) -> None:
await self.message.channel.send("Timed out!", ephemeral=True)
await self.disable_all_items()
@discord.ui.button(label="Hello", style=discord.ButtonStyle.success)
async def hello(self, interaction: discord.Interaction, button: discord.ui.Button):
await interaction.response.send_message("World")
@discord.ui.button(label="Cancel", style=discord.ButtonStyle.red)
async def cancel(self, interaction: discord.Interaction, button: discord.ui.Button):
await interaction.response.send_message("Cancelling")
@app_commands.command()
async def button(ctx):
view = SimpleView(timeout=10)
# button = discord.ui.Button(label="Click me")
# view.add_item(button)
message = await ctx.send("Click the button!", view=view)
view.message = message
await view.wait()
class FeedbackModal(discord.ui.Modal, title="Send us your feedback"):
fb_title = discord.ui.TextInput(
style=discord.TextStyle.short,
label="Title",
required=False,
placeholder="Give your feedback a title"
)
message = discord.ui.TextInput(
style=discord.TextStyle.long,
label="Message",
required=True,
max_length=500,
placeholder="Write your feedback here"
)
async def on_submit(self, interaction: discord.Interaction):
channel = interaction.guild.get_channel(1201498462471077948) # feedback channel here
embed = discord.Embed(title="New Feedback", description=self.message.value)
embed.set_author(name=self.user.nick)
await channel.send(embed=embed)
await interaction.response.send_message(f"Thank you, {self.user.mention}!", ephemeral=True)
async def on_error(self, interaction: discord.Interaction):
pass
@app_commands.command()
async def feedback(interaction: discord.Interaction):
feedback_modal = FeedbackModal()
feedback_modal.user = interaction.user
await interaction.response.send_modal(feedback_modal)
class SurveyView(discord.ui.View):
answer1 = None
answer2 = None
@discord.ui.select(
placeholder="What is your age?",
options=[
discord.SelectOption(label="1", value="1"),
discord.SelectOption(label="2", value="2"),
discord.SelectOption(label="3", value="3"),
],
max_values=1
)
async def select_age(self, interaction: discord.Interaction, select_item : discord.ui.Select):
self.answer1 = select_item.values
@app_commands.command()
async def survey(interaction: discord.Interaction):
view = SurveyView()
await interaction.response.send(view=view)