Rapptz / discord.py

An API wrapper for Discord written in Python.
http://discordpy.rtfd.org/en/latest
MIT License
14.84k stars 3.76k forks source link

Random 404-Unknown interaction Errors (code: 10062) #9507

Closed 5-30 closed 1 year ago

5-30 commented 1 year ago

Summary

Random 404 errors pop up, I'm pretty sure sending a modal shouldn't take more than 5 seconds though.

Reproduction Steps

I ran the command /reupload with this code.

Minimal Reproducible Code

intents = discord.Intents.default()
intents.typing = False
intents.presences = False
intents.reactions = True
intents.members = True
intents.guilds = True

bot = commands.Bot(command_prefix="/", intents=intents)

@bot.event
async def on_ready():
    await bot.change_presence(activity=discord.Game(name="https://tiktools.fr/"))
    print(f"Bot is ready. Logged in as {bot.user.name}")
    synced = await bot.tree.sync()
    print(f"synced {len(synced)} command(s)")

@bot.tree.command(name="reupload", description="Génère une vidéo TikTok à partir d'un extrait de vidéo YouTube")
async def reupload(interaction: discord.Interaction):
    if interaction.user.id in active:
            await interaction.followup.send("Merci d'attendre la fin de l'opération précédente avant d'en démarrer une nouvelle !", ephemeral=True)
            return
    await interaction.response.send_modal(ReuploadModal())

bot.run([Token])

Where ReuploadModal is obviously defined as some modal.

Expected Results

I expected a modal to open for me to enter what I need the bot to do.

Actual Results

The modal opened, but I get this error :

2023-07-23 01:08:43 ERROR    discord.app_commands.tree Ignoring exception in command 'reupload'
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/dist-packages/discord/app_commands/commands.py", line 828, in _do_call
    return await self._callback(interaction, **params)  # type: ignore
  File "/root/test.py", line 737, in reupload
    await interaction.response.send_modal(ReuploadModal())
  File "/usr/local/lib/python3.9/dist-packages/discord/interactions.py", line 972, in send_modal
    await adapter.create_interaction_response(
  File "/usr/local/lib/python3.9/dist-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 "/usr/local/lib/python3.9/dist-packages/discord/app_commands/tree.py", line 1248, in _call
    await command._invoke_with_namespace(interaction, namespace)
  File "/usr/local/lib/python3.9/dist-packages/discord/app_commands/commands.py", line 853, in _invoke_with_namespace
    return await self._do_call(interaction, transformed_values)
  File "/usr/local/lib/python3.9/dist-packages/discord/app_commands/commands.py", line 846, in _do_call
    raise CommandInvokeError(self, e) from e
discord.app_commands.errors.CommandInvokeError: Command 'reupload' raised an exception: NotFound: 404 Not Found (error code: 10062): Unknown interaction

It may seem as not that big of a deal, but it can completely break other parts of my code where I need to retrieve infos related to the response object.

Intents

See the code.

System Information

Checklist

Additional Context

Another weird thing is the randomness of this error. Sometimes it pops up 3 times in a row, sometimes it just never does.

Rapptz commented 1 year ago

This error happens if you don't respond within 3 seconds. Your minimal example does not have enough code to showcase this, though I'm assuming the real code you're using (since there are over 700 lines of code in it) is doing some computations that add up or is using blocking code. Note that your original code is also doing a followup before responding, this is a mistake.

This is not an issue with the library either way, and unfortunately I cannot help you debug this issue myself.