Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 18819

"The application did not respond" when running "Purge" command with a discord bot. Why is this happening?

$
0
0

Everytime I run my command "purge" on my Discord bot, I keep seeing "The application did not respond" after the command runs and deletes the limited messages. I'm using discord.app_commands (I believe) and tree for my commands so they can run as slash commands.

What happens after running the "purge" slash command.

Here are my imports:

import discordfrom discord import app_commandsfrom discord.ext import commandsfrom asyncio import sleep

Here is the command:

@tree.command(    name="purge",    description="Deletes a specified number of messages from the channel.")async def purge(interaction, limit: int):    try:        if interaction.user.guild_permissions.manage_messages:            await interaction.channel.purge(limit=limit + 1)            await sleep(2)            await interaction.response.send_message(f"{limit} messages deleted!", ephemeral=True)        else:            await interaction.response.send_message("You don't have permission to use this command.", ephemeral=True)    except discord.errors.NotFound:        # Handle the case where the interaction is not found        await interaction.response.send_message("An error occurred while processing the command. Please try again later.", ephemeral=True)    except discord.errors.Forbidden:        # Handle the case where the bot doesn't have permission to perform the action        await interaction.response.send_message("I don't have permission to perform this action.", ephemeral=True)    except Exception as e:        # Handle any other exceptions that might occur        await interaction.response.send_message(f"An unexpected error occurred: {str(e)}", ephemeral=True)

This error occurs ONLY when I run purge, no other command I have has caused this. I did "/purge" with a limit block of any integer, and after the bot deletes the specific amount of messages, I expected it to appear with "{limit} messages deleted!" but instead, it says "The application did not respond." I tried making the bot wait 2 seconds before sending the message, but it didn't work either.

Also, the Traceback from my server console:

2024-04-09 00:22:43 ERROR    discord.app_commands.tree Ignoring exception in command 'purge'Traceback (most recent call last):  File "/home/container/bot_commands.py", line 27, in purge    await interaction.response.send_message(f"{limit} messages deleted!", ephemeral=True)  File "/home/container/.local/lib/python3.12/site-packages/discord/interactions.py", line 801, in send_message    await adapter.create_interaction_response(  File "/home/container/.local/lib/python3.12/site-packages/discord/webhook/async_.py", line 219, in request    raise NotFound(response, data)discord.errors.NotFound: 404 Not Found (error code: 10062): Unknown interactionDuring handling of the above exception, another exception occurred:Traceback (most recent call last):  File "/home/container/.local/lib/python3.12/site-packages/discord/app_commands/commands.py", line 828, in _do_call    return await self._callback(interaction, **params)  # type: ignore           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  File "/home/container/bot_commands.py", line 33, in purge    await interaction.response.send_message("An error occurred while processing the command. Please try again later.", ephemeral=True)  File "/home/container/.local/lib/python3.12/site-packages/discord/interactions.py", line 801, in send_message    await adapter.create_interaction_response(  File "/home/container/.local/lib/python3.12/site-packages/discord/webhook/async_.py", line 219, in request    raise NotFound(response, data)discord.errors.NotFound: 404 Not Found (error code: 10062): Unknown interactionThe above exception was the direct cause of the following exception:Traceback (most recent call last):  File "/home/container/.local/lib/python3.12/site-packages/discord/app_commands/tree.py", line 1248, in _call    await command._invoke_with_namespace(interaction, namespace)  File "/home/container/.local/lib/python3.12/site-packages/discord/app_commands/commands.py", line 853, in _invoke_with_namespace    return await self._do_call(interaction, transformed_values)           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  File "/home/container/.local/lib/python3.12/site-packages/discord/app_commands/commands.py", line 846, in _do_call    raise CommandInvokeError(self, e) from ediscord.app_commands.errors.CommandInvokeError: Command 'purge' raised an exception: NotFound: 404 Not Found (error code: 10062): Unknown interaction

Viewing all articles
Browse latest Browse all 18819

Trending Articles