SGA-A / c2c

Source code for the custom app exclusive to cc, where most interactions begin and end.
MIT License
1 stars 0 forks source link

No viable error handler for non-deferred interactions #4

Closed SGA-A closed 8 months ago

SGA-A commented 8 months ago

Summary

For commands that contain an interaction that is not being deferred, and an error is being handled, the interaction is successfully deferred to respond accordingly but it raises the error:

discord.errors.InteractionResponded: This interaction has already been responded to before

Additional Context

The error handler for interaction-based contexts automatically tries to defer the response if it is not already. This is done by acknowledging if the interaction is done or not:

https://github.com/SGA-A/c2c/blob/131f55acfd526238310fcfce8a52cdfa04b4f00e/cogs/slash-events.py#L23-L24

We are looking into the issue, but note that this does not actually prevent the command from being executed after an error was found in the error handler.

SGA-A commented 8 months ago
Traceback (most recent call last):
  File "C:\Python\Lib\site-packages\discord\app_commands\commands.py", line 827, in _do_call
    return await self._callback(self.binding, interaction, **params)  # type: ignore
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "economy.py", line 2224, in highlow
    await interaction.response.send_message(f"I am thinking of a number. Guess what it is. **{hint}!**", # type: ignore
  File "C:\Python\Lib\site-packages\discord\interactions.py", line 774, in send_message
    raise InteractionResponded(self._parent)
discord.errors.InteractionResponded: This interaction has already been responded to before

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

Traceback (most recent call last):
  File "C:\Python\Lib\site-packages\discord\app_commands\tree.py", line 1248, in _call
    await command._invoke_with_namespace(interaction, namespace)
  File "C:\Python\Lib\site-packages\discord\app_commands\commands.py", line 853, in _invoke_with_namespace
    return await self._do_call(interaction, transformed_values)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python\Lib\site-packages\discord\app_commands\commands.py", line 846, in _do_call
    raise CommandInvokeError(self, e) from e
discord.app_commands.errors.CommandInvokeError: Command 'highlow' raised an exception: InteractionResponded: This interaction has already been responded to before

I have found a situation in which this took place. The attachment shows exactly what happened:

error_raised

This issue for highlow has now been fixed in this commit: https://github.com/SGA-A/c2c/commit/37350ad928ab9c0de26faea70bf8839491b5cfd8.

The issue however will remain open in the case that the same issue is found elsewhere.

SGA-A commented 8 months ago

We are still encountering this issue in rare situations. We are looking into this. No ETA can be given.

SGA-A commented 8 months ago

The causes have been identified. The issue was occuring due to responding to an interaction despite already sending a response prior. This is not news to most of us however, as we are aware of this. Deferring an interaction was one way this could happen, which was a method I was not aware of myself until I delved into the docs. Seeing as the main root cause has been identified, I'm closing this issue, the title of the issue has been resolved and there are no additional changes needed.