-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathinitial_view.py
72 lines (51 loc) · 1.94 KB
/
initial_view.py
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
import settings
import discord
from discord.ext import commands
import utils
logger = settings.logging.getLogger("bot")
class SimpleView(discord.ui.View):
foo : bool = None
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("Timedout")
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")
self.foo = True
self.stop()
@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")
self.foo = False
self.stop()
def run():
intents = discord.Intents.default()
intents.message_content = True
bot = commands.Bot(command_prefix="!", intents=intents)
@bot.event
async def on_ready():
await utils.load_videocmds(bot)
@bot.command()
async def button(ctx):
view = SimpleView(timeout=50)
# button = discord.ui.Button(label="Click me")
# view.add_item(button)
message = await ctx.send(view=view)
view.message = message
await view.wait()
await view.disable_all_items()
if view.foo is None:
logger.error("Timeout")
elif view.foo is True:
logger.error("Ok")
else:
logger.error("cancel")
bot.run(settings.DISCORD_API_SECRET, root_logger=True)
if __name__ == "__main__":
run()