Command raised an exception: NotFound: 404 Not Found (error code: 0): Interaction is unknown (you have already responded to the interaction)

Viewed 67

Here is my code. It throws the following exception when I use the command second time. discord.ext.commands.errors.CommandInvokeError: Command raised an exception: NotFound: 404 Not Found (error code: 0): Interaction is unknown (you have already responded to the interaction or responding took too long)

For Example, First if I use "button hi" command and click the button it returns hi. At second time when I use the same command "button hello" and click the button, this time it throws the above exception and returns "hi" but not "hello".

    @bot.command()
    async def button(ctx, *, args):
      await ctx.send("hello", components=[
        [Button(label="Hi", style="3", custom_id="button1")]
      ])
      while True:
        interaction = await bot.wait_for("button_click", check=lambda i: i.custom_id == "button1")
        await interaction.send(content=args, ephemeral=True)

I am using discord_components library. Sorry for bad explanation. Any help would be appreciated.

1 Answers

I found the answer through the discord_components official discord server. I needed to check on what message was clicked by using it's id.

@bot.command()
async def button(ctx, *, args):
  message = await ctx.send("hello", components=[
    [Button(label="Hi", style="3", custom_id="button1")]
  ])
  while True:
    interaction = await bot.wait_for("button_click", check=lambda i: i.message.id == message.id)
    await interaction.send(content=args, ephemeral=True)
Related