Pycord Unknown Interaction 404 Error - How to fix?

Well, after some looking here are things to note:

  • If you are going to use ephemeral=True, you need to use it on defer and on response
  • The message not found means the message you are trying modify has been deleted/does not exist, which is odd, since you are not replying/modifying.
    Also, did you change the code? The tracebacks are no longer accurate, could you post them again?

No, I reset the code back to what it was before.

Still seems different? Can you add ephemeral=True to ctx.defer, and then post the whole trace back again? I will help tomorrow.

The embeds work perfectly when I don’t have await ctx.channel.purge(limit=amount, check=not_pinned). However, when I do have it, the purging works — it purges the correct amount of messages — but it only displays the embed for 0, negative purges, and 1. Otherwise, it gives the following error:

Ignoring exception in command purge:
Traceback (most recent call last):
  File "/home/runner/Presto/venv/lib/python3.10/site-packages/discord/commands/core.py", line 124, in wrapped
    ret = await coro(arg)
  File "/home/runner/Presto/venv/lib/python3.10/site-packages/discord/commands/core.py", line 982, in _invoke
    await self.callback(ctx, **kwargs)
  File "main.py", line 137, in purge
    await ctx.defer(ephemeral=True)
  File "/home/runner/Presto/venv/lib/python3.10/site-packages/discord/interactions.py", line 655, in defer
    await self._locked_response(
  File "/home/runner/Presto/venv/lib/python3.10/site-packages/discord/interactions.py", line 1090, in _locked_response
    await coro
  File "/home/runner/Presto/venv/lib/python3.10/site-packages/discord/webhook/async_.py", line 219, in request
    raise NotFound(response, data)
discord.errors.NotFound: 404 Not Found (error code: 10062): Unknown interaction

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/runner/Presto/venv/lib/python3.10/site-packages/discord/bot.py", line 1114, in invoke_application_command
    await ctx.command.invoke(ctx)
  File "/home/runner/Presto/venv/lib/python3.10/site-packages/discord/commands/core.py", line 375, in invoke
    await injected(ctx)
  File "/home/runner/Presto/venv/lib/python3.10/site-packages/discord/commands/core.py", line 132, in wrapped
    raise ApplicationCommandInvokeError(exc) from exc
discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: NotFound: 404 Not Found (error code: 10062): Unknown interaction

Do you have a solution yet? I provided you with the complete error.

Try one of these: Pycord v2.4 Documentation

I am pretty sure this is either a bug or something only someone with lots of pycord experience can solve.

I tested this and it worked. I just added a defer on top of the existing code and removed the defer at the end of it.

Btw now its deleting 100 of my messages :sob:

@bot.slash_command(name="purge", description="Mass delete a custom amount of messages! This command does not deleted pinned messages.")
@has_permissions(administrator=True)
async def purge(ctx, amount: int):
  await ctx.defer()
  def not_pinned(msg):
    return not msg.pinned
  if amount < 0:
    purgeEmbed = discord.Embed(title="Message Purge", description="You can't purge negative messages! Wouldn't that be adding messages?", color=0xff0000)
  elif amount == 0:
    purgeEmbed = discord.Embed(title="Message Purge", description="Zero messages, really?", color=0xff0000)
  elif amount == 1:
    purgeEmbed = discord.Embed(title="Message Purge", description="You successfully purged 1 message.", color=0x00ff00)
    await ctx.channel.purge(limit=amount, check=not_pinned)
  elif amount > 1:
    purgeEmbed = discord.Embed(title="Message Purge", description="You successfully purged messages.", color=0x00ff00)
    await ctx.channel.purge(limit=amount, check=not_pinned)
  else:
    print("Presto's gone Largo. Something went wrong. Ed: purge")
    purgeEmbed.set_image(url="https://media.discordapp.net/attachments/737732516588290110/1084510457387307048/presto-purge.png")
	#await ctx.defer(ephemeral=True)
  await ctx.respond(embed=purgeEmbed, ephemeral=True)

1 Like

I will test this out on the weekend. I hope this works. I’ll mark your reply as correct/answered if it works for me. Thanks!

1 Like

This is how to properly use ctx.defer yes, I thought I already said that up there somewhere but ig not. Probably should have specified that defer is a one-time thing and should be never called twice.

Edit:

:eyes:

I decided to test it just now, but it didn’t work. It gave me the an Unknown Message error. I copied and pasted the code you had. Here’s the error:

Ignoring exception in command purge:
Traceback (most recent call last):
  File "/home/runner/Presto/venv/lib/python3.10/site-packages/discord/commands/core.py", line 124, in wrapped
    ret = await coro(arg)
  File "/home/runner/Presto/venv/lib/python3.10/site-packages/discord/commands/core.py", line 982, in _invoke
    await self.callback(ctx, **kwargs)
  File "main.py", line 138, in purge
    await ctx.respond(embed=purgeEmbed, ephemeral=True)
  File "/home/runner/Presto/venv/lib/python3.10/site-packages/discord/commands/context.py", line 286, in respond
    return await self.followup.send(*args, **kwargs)  # self.send_followup
  File "/home/runner/Presto/venv/lib/python3.10/site-packages/discord/webhook/async_.py", line 1745, in send
    data = await adapter.execute_webhook(
  File "/home/runner/Presto/venv/lib/python3.10/site-packages/discord/webhook/async_.py", line 219, in request
    raise NotFound(response, data)
discord.errors.NotFound: 404 Not Found (error code: 10008): Unknown Message

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/runner/Presto/venv/lib/python3.10/site-packages/discord/bot.py", line 1114, in invoke_application_command
    await ctx.command.invoke(ctx)
  File "/home/runner/Presto/venv/lib/python3.10/site-packages/discord/commands/core.py", line 375, in invoke
    await injected(ctx)
  File "/home/runner/Presto/venv/lib/python3.10/site-packages/discord/commands/core.py", line 132, in wrapped
    raise ApplicationCommandInvokeError(exc) from exc
discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: NotFound: 404 Not Found (error code: 10008): Unknown Message

I have to go now, so I may check tomorrow, or on the weekend, or right now, so please respond ASAP.

GOOD NEWS! I GOT IT TO WORK. I just added ephemeral=True to ctx.defer() and now it works. However, the image is not appearing in the embed.

1 Like

Here’s the code that works:

@bot.slash_command(name="purge", description="Mass delete a custom amount of messages! This command does not deleted pinned messages.")
@has_permissions(administrator=True)
async def purge(ctx, amount: int):
  await ctx.defer(ephemeral=True)
  def not_pinned(msg):
    return not msg.pinned
  if amount < 0:
    purgeEmbed = discord.Embed(title="Message Purge", description="You can't purge negative messages! Wouldn't that be adding messages?", color=0xff0000)
  elif amount == 0:
    purgeEmbed = discord.Embed(title="Message Purge", description="Zero messages, really?", color=0xff0000)
  elif amount == 1:
    purgeEmbed = discord.Embed(title="Message Purge", description="You successfully purged 1 message.", color=0x00ff00)
    await ctx.channel.purge(limit=amount, check=not_pinned)
  elif amount > 1:
    purgeEmbed = discord.Embed(title="Message Purge", description="You successfully purged messages.", color=0x00ff00)
    await ctx.channel.purge(limit=amount, check=not_pinned)
  else:
    print("Presto's gone Largo. Something went wrong. Ed: purge")
    purgeEmbed.set_image(url="https://media.discordapp.net/attachments/737732516588290110/1084510457387307048/presto-purge.png")
  await ctx.respond(embed=purgeEmbed, ephemeral=True)

The image doesn’t work, but I’ll figure it out. Thank you all so much :slight_smile:

2 Likes

I fixed the image problem. I don’t know why it wasn’t working but I just updated the link to the image.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.