Closed helish88 closed 3 years ago
It would be better if you use break
instead of stop
Agree. ill change
Could you divide the file?
I think it will crash because of on_button_click
code
@bot.command()
async def buttons(ctx):
"""Buttons example of navigation with while and with check"""
msg = await ctx.channel.send(embed=discord.Embed(color=discord.Color.random(), title="Navigation"),
components=[
[Button(style=ButtonStyle.blue, label="Backward", emoji="⏮️"),
Button(style=ButtonStyle.red, label="Stop", emoji="❌"),
Button(style=ButtonStyle.blue, label="Forward", emoji="⏭️")]])
def check(m):
return m.user == ctx.author and m.message.channel == ctx.channel
while True:
try:
res = await bot.wait_for("button_click", check=check, timeout=60)
except asyncio.TimeoutError:
await msg.delete()
await ctx.send(embed=discord.Embed(color=discord.Color.red(),
title="Timeout"))
break
if res.channel == ctx.channel:
if res.component.label == "Forward":
await msg.edit(embed=discord.Embed(color=discord.Color.random(),
title="Forward"))
await res.respond(
type=InteractionType.DeferredUpdateMessage
)
elif res.component.label == "Backward":
await msg.edit(embed=discord.Embed(color=discord.Color.random(),
title="Backward"))
await res.respond(
type=InteractionType.DeferredUpdateMessage
)
elif res.component.label == "Stop":
await msg.edit(embed=discord.Embed(color=discord.Color.random(),
title="Stop"))
await res.respond(
type=InteractionType.UpdateMessage
)
await msg.delete()```
and wdym Could you divide the file?
this is one command
Why open two PRs
PR TYPE
Checks