Hello !
I actually got this error that is annoying, it happen on multiple commands of my bot, including the ones with an autocomplete :
Ignoring exception in command translate:
Traceback (most recent call last):
File "/usr/local/lib/python3.12/site-packages/discord/commands/core.py", line 131, in wrapped
ret = await coro(arg)
^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/discord/commands/core.py", line 1009, in _invoke
await self.callback(self.cog, ctx, **kwargs)
File "/app/cogs/translate.py", line 64, in translate
await ctx.defer(ephemeral=ephemeral)
File "/usr/local/lib/python3.12/site-packages/discord/interactions.py", line 748, in defer
await self._locked_response(
File "/usr/local/lib/python3.12/site-packages/discord/interactions.py", line 1243, in _locked_response
await coro
File "/usr/local/lib/python3.12/site-packages/discord/webhook/async_.py", line 220, 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.12/site-packages/discord/bot.py", line 1130, in invoke_application_command
await ctx.command.invoke(ctx)
File "/usr/local/lib/python3.12/site-packages/discord/commands/core.py", line 376, in invoke
await injected(ctx)
File "/usr/local/lib/python3.12/site-packages/discord/commands/core.py", line 139, in wrapped
raise ApplicationCommandInvokeError(exc) from exc
discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: NotFound: 404 Not Found (error code: 10062): Unknown interaction
For the command that made the error, here is the code :
class Translate(Cog):
def __init__(self, bot):
self.bot = bot
#########################
# autocomplete function #
#########################
async def get_languages(ctx: AutocompleteContext):
filtered_languages = [lang for lang in LANGUAGES if lang.startswith(ctx.value.lower())]
if len(filtered_languages) > 25:
return filtered_languages[:25]
else:
return filtered_languages
#############
# translate #
#############
@slash_command(
name="translate",
description="Translate a text from a language to another.",
guild_only=True
)
@option(
name="text",
description="The text you want to translate.",
required=True,
type=str
)
@option(
name="to_language",
description="The language you want to translate the text into.",
required=True,
type=str,
autocomplete=basic_autocomplete(get_languages)
)
@option(
name="from_language",
description="The language of your actual text.",
required=False,
type=str,
autocomplete=basic_autocomplete(get_languages)
)
@option(
name="ephemeral",
description="if you want the answer to be visible only to you. Default is False",
required=False,
type=bool
)
async def translate(self, ctx : ApplicationContext, text, to_language, from_language = None, ephemeral = False):
await ctx.defer(ephemeral=ephemeral)
try :
if from_language is None :
traduction = trad.translate(text, dest=to_language)
else :
traduction = trad.translate(text, dest=to_language, src=from_language)
except :
await ctx.respond("An error occured while translating the text.\nPlease try again.", ephemeral=True)
return
await ctx.respond(f"{traduction.text}", ephemeral=ephemeral)
def setup(bot):
print("Translate Command is ready !")
bot.add_cog(Translate(bot))