Search code examples
pythondiscordbotsnextcord

How to fix a nextcord.errors.ApplicationInvokeError


I am investigating why I am getting this error with my Python Discord bot. I'm using Python in VScode with the Nextcord library. It works a bit and them throws this error:

Ignoring exception in command <nextcord.application_command.SlashApplicationCommand object at 0x000002379C4C7730>:
Traceback (most recent call last):
  File "C:\Users\jonat\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\nextcord\application_command.py", line 863, in invoke_callback_with_hooks
    await self(interaction, *args, **kwargs)
  File "C:\Users\jonat\OneDrive\Documents\DiscordBot\main.py", line 53, in arem
    await interaction.response.send_message("||**Cal Jordan:** Instant message from... AREM!!||", files=[nextcord.File('AREM.mp3')])
  File "C:\Users\jonat\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\nextcord\interactions.py", line 895, in send_message
    await adapter.create_interaction_response(
  File "C:\Users\jonat\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\nextcord\webhook\async_.py", line 204, in request
    raise NotFound(response, data)
nextcord.errors.NotFound: 404 Not Found (error code: 10062): Unknown interaction

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

nextcord.errors.ApplicationInvokeError: Command raised an exception: NotFound: 404 Not Found (error code: 10062): Unknown interaction

Solution

  • "Unknown interaction" pretty much always means you are taking too long to respond.

    Discord allows 3 seconds to respond. If you want to extend that, you can use await interaction.response.defer() at the beginning of the function to show "bot is thinking" for up to 15 minutes to allow you time to respond.

    See https://docs.nextcord.dev/en/stable/interactions.html#deferred-response for more info.