bot will send an emblem that will contain 1 green button After clicking this button, the user's nickname on the Discord server will be displayed on the emblem and there will be a timer next to it. like thisin photo
but when i click that there's an error "This action failed"
import discord
from discord.ext import commands
from discord.ui import Button, View
bot = commands.Bot(command_prefix='?', intents=discord.Intents.all())
bot.remove_command('help')
@bot.event
async def on_ready():
print(f'Logged in as {bot.user.name} {bot.user.id}')
print('------')
@bot.command()
async def tablet(ctx):
embed = discord.Embed(title="◣**Tablet Ochrony**◢",
description="Click Start to begin the timer",
color=0b000000)
embed.add_field(name="Imię i Nazwisko |⏳Na służbie:",
value="None",
inline=False)
embed.add_field(name="Time Elapsed:", value="0 seconds", inline=False)
start_button = Button(style=discord.ButtonStyle.green,
label="Status 1",
custom_id="button1")
stop_button = Button(style=discord.ButtonStyle.red,
label="Status 3",
custom_id="button2")
pause_button = Button(style=discord.ButtonStyle.blurple,
label="Status 2",
custom_id="button3")
view = View()
view.add_item(start_button)
view.add_item(pause_button)
view.add_item(stop_button)
reset_button = Button(style=discord.ButtonStyle.grey,
label="Odejmij czas",
custom_id="Reset")
view.add_item(reset_button)
message = await ctx.send(embed=embed, view=view)
# interaction = await bot.wait_for("button_click", check = lambda i: i.custom_id == "button1")
# ------------------------------------------------------------------------------------
interaction = await bot.wait_for(
"button_click",
check=lambda i: i.user.id == ctx.author.id and i.message.id == message.id
.custom_id == "button1"
)
# ------------------------------------------------------------------------------------
if interaction.custom_id == "button1":
nickname = ctx.author.display_name
embed.set_field_at(0,
name="Imię i Nazwisko |⏳Na służbie:",
value=nickname,
inline=False)
await message.edit(embed=embed, view=view)
elif interaction.custom_id == "button3":
embed.set_field_at(0,
name="Imię i Nazwisko |⏳Na służbie:",
value="None",
inline=False)
await message.edit(embed=embed, view=view)
bot.run('token')
The way you're performing an interaction check is very inefficient, you should rather use the
discord.uimodule for doing the same (docs), here's an example for the same: