Pycord Unknown Interaction 404 Error - How to fix?

I am using pycord, a fork of discord.py, to create a discord bot. However, I ran into a problem. I am making a moderation bot and the purge command isn’t working. The other commands are working just fine.

Here is my code:

@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):
	def not_pinned(msg):
		return not msg.pinned
	if round(amount, 1) < 0:
		purgeEmbed = discord.Embed(title="Message Purge", description="You can't purge negative messages! Wouldn't that be adding messages?", color=0xff0000)
	elif round(amount, 1) == 0:
		purgeEmbed = discord.Embed(title="Message Purge", description="Zero messages, really?", color=0xff0000)
	elif round(amount, 1) == 1:
		await ctx.channel.purge(limit=amount, check=not_pinned)
		purgeEmbed = discord.Embed(title="Message Purge", description="You successfully purged 1 message.", color=0x00ff00)
	elif round(amount, 1) > 1:
		await ctx.channel.purge(limit=amount, check=not_pinned)
		purgeEmbed = discord.Embed(title="Message Purge", description="You successfully purged messages.", color=0x00ff00)
	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)

Since everything else is working fine, I didn’t include the rest of my code, but if you need it, then just tell me.

The purge command works when you put in a negative value as the amount, or 0 or 1 as an amount. It does what it is supposed to. If you put in a negative value, it says “You can’t purge negative messages! Wouldn’t that be adding messages?” If you put in 0, it says, “Zero messages, really?” If you put in 1, it says, “You successfully purge 1 message.”

However, when I try to purge MORE than 1 message, it says, “This interaction failed” in discord and in the console, it says:

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 121, in purge
    await interaction.response.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

Does anyone know how to fix it? I’m not in a hurry to finish this, but it would be great if my question would be answered as fast as possible. If you need any more information about the situation or the code, just ask. Thanks!

Idk, but in this: Slash Commands | Pycord Guide It says just to use bot.command, not bot.slash_command.

Thank you for your response. I see both @bot.command and @bot.slash_command, but I don’t think that that’s the problem because my other commands are working perfectly.

1 Like

Based on this: python - Error: discord.errors.NotFound: 404 Not Found (error code: 10062): Unknown interaction discord.py when sending a gif in embed - Stack Overflow, I think your purge is taking too long, and the interaction gets deleted. Even though this post is for discord.py, I checked the Pycord docs and it should work.

I did try deferring it already. I think I’ll try it again, though. Thank you, and I’ll see if it works.

1 Like

I’m not exactly sure how it works, but I think I’m supposed to do:

async def purge(interaction: discord.Interaction, amount: int):

instead of:

async def purge(ctx, amount: int)

Could you verify?

No, you run purge on a channel, so neither would work. Your old method should work.

Docs: Discord Models - Pycord v2.4 Documentation

I have to go now, so I’ll look into it later. Thanks!

1 Like

How would I incorporate what it says on the stackoverflow post? Could you maybe provide some code as an example?

I’m not exactly sure, but do you mean that I should do

ctx.response.defer()

and that sort of thing, or something else?

I am pretty sure based on these docs that you just do await ctx.defer(). Just add that first and leave all the other code be. Does it work?

Where should I put await ctx.defer()? When I add it before await ctx.respond(embed=purgeEmbed, ephemeral=True), purging multiple messages still does not work. However, if I put await ctx.defer() at the very beginning of the function, it gives me an Unkown Message 404 Not Found error (code: 10008). I checked the docs and still am not sure where to put it, as I have also tried multiple spots. Thanks so far!

Can you show the code for it when you put it at the beginning?

Here:

@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 round(amount, 1) < 0:
		purgeEmbed = discord.Embed(title="Message Purge", description="You can't purge negative messages! Wouldn't that be adding messages?", color=0xff0000)
	elif round(amount, 1) == 0:
		purgeEmbed = discord.Embed(title="Message Purge", description="Zero messages, really?", color=0xff0000)
	elif round(amount, 1) == 1:
		await ctx.channel.purge(limit=amount, check=not_pinned)
		purgeEmbed = discord.Embed(title="Message Purge", description="You successfully purged 1 message.", color=0x00ff00)
	elif round(amount, 1) > 1:
		await ctx.channel.purge(limit=amount, check=not_pinned)
		purgeEmbed = discord.Embed(title="Message Purge", description="You successfully purged messages.", color=0x00ff00)
	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)

And the full error? I am at 3% rn, so I will look tomorrow.

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 129, 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
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 129, 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

Here is the full error.

@dragonhunter1 Are you there? I posted the full error above. Can you check it out?

Could you link the repl (not invite)? that would really be helpful

Found their Replit profile but Idk which Repl it is, might be private, I looked through all their Python Repls from recently and I couldn’t find it.

https://replit.com/@Wadwad/Presto

It’s on a team. That’s why you couldn’t find it.

I’ve been playing around with the command and I get a few errors.

I get, of course, Unknown Interaction 404.

I also get, sometimes, Unknown Message 404.

Also, repl.it has a rate limit, which I find rather annoying, as I am constantly getting 429 Too Many Requests.

After you try to help me with Unknown Interaction and the other errors keep showing up, it would be great if you could help me with that. However, it will likely work if we fix the Unknown Interaction error.