plon / Bard-Discord-bot

Integrate Google Bard into your own discord chatbot

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Exception when using /chat command

revblueldd opened this issue · comments

If I try something short like "/chat testing123" it works, but if I try a sentence like "/chat What about longer sentences?" and "/chat is it because of the question mark", both fail.

[2023-05-18 15:53:14] [ERROR ] discord.app_commands.tree: Ignoring exception in command 'chat'
Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\app_commands\commands.py", line 842, in _do_call
return await self.callback(interaction, **params) # type: ignore
File "C:\Bard-Discord-bot\main.py", line 139, in chat
await interaction.response.send_message(interaction_response, allowed_mentions=allowed_mentions)
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\interactions.py", line 778, in send_message
await adapter.create_interaction_response(
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\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 "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\app_commands\tree.py", line 1248, in _call
await command._invoke_with_namespace(interaction, namespace)
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\app_commands\commands.py", line 867, in _invoke_with_namespace
return await self._do_call(interaction, transformed_values)
File "C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\app_commands\commands.py", line 860, in _do_call
raise CommandInvokeError(self, e) from e
discord.app_commands.errors.CommandInvokeError: Command 'chat' raised an exception: NotFound: 404 Not Found (error code: 10062): Unknown interaction

"/chat two words" also fails. Maybe it's spaces?

commented

Fixed. I forgot to include interaction.response.defer(). The issue was that messages with more than one word usually take more than three seconds to process and without deferring the response for messages that take more than 3 seconds to process, you get a 404.

Confirmed fixed, thank you!