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!