interactions.py icon indicating copy to clipboard operation
interactions.py copied to clipboard

[BUG] Autodefer not always working

Open JoinChang opened this issue 3 years ago • 6 comments

Describe the bug.

This happens when the command is not responded to for three seconds. image

Example: https://autocode.com/autocode/threads/how-to-avoid-timeout-errors-when-responding-to-discord-interactions-tutorial-9f4b312c/

List the steps.

  1. Create a slash command and listen to it
  2. Create a time-consuming method
  3. Command is processing, but few seconds later, Discord returns a new interaction
  4. Library doesn't process the interaction normally, returned: Unknown interaction, with code '10062' and severity '40'

What you expected.

Should listen for timeout events.

What you saw.

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/interactions/client/models/command.py", line 920, in wrapper
    raise e
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/interactions/client/models/command.py", line 906, in wrapper
    return await coro(ctx, *args, **kwargs)
  File "/Volumes/NTFS/LxBot-Yukimi-Project/lxbot-core/core/adapters/discord/__init__.py", line 39, in _
    await option["func"](self, ctx, **kwargs) # 回调函数
  File "/Volumes/NTFS/LxBot-Yukimi-Project/lxbot-core/modules/bilibili/main.py", line 19, in _
  File "/Volumes/NTFS/LxBot-Yukimi-Project/lxbot-core/core/adapters/discord/__init__.py", line 18, in reply
    await command_send(ctx, **MessageParser().parseArguments(content))
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/interactions/ext/files/files.py", line 356, in command_send
    await Inter_Request.create_interaction_response(
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/interactions/ext/files/files.py", line 63, in create_interaction_response
    return await self._req.request(
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/interactions/api/http/request.py", line 174, in request
    raise LibraryException(
interactions.api.error.LibraryException: An error occurred:
Unknown interaction, with code '10062' and severity '40'

What version of the library did you use?

release

Version specification

4.3.0

Code of Conduct

  • [X] I agree to follow the contribution requirements.

JoinChang avatar Aug 18 '22 05:08 JoinChang

Hey! This is a common issue with blocking code, which seems to fit in with what you just described.

Blocking code, like really long synchronous tasks (IE the one you described) tends to halt the async "event loop", the logic controlling async as a whole. As interactions.py is async, this means you are effectively halting it from being able to do anything.

For more information, you can look at the Pycord entry about this. You may need to run your code in an "executor," or rethink what you are doing in general to use more asynchronous means.

AstreaTSS avatar Aug 18 '22 05:08 AstreaTSS

To increase time limit up to 15 minutes you should defer your interaction via ctx.defer

Damego avatar Aug 18 '22 05:08 Damego

To increase time limit up to 15 minutes you should defer your interaction via ctx.defer

Thank you!

JoinChang avatar Aug 18 '22 05:08 JoinChang

To increase time limit up to 15 minutes you should defer your interaction via ctx.defer

image

It still randomly returns this error:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/interactions/client/models/command.py", line 920, in wrapper
    raise e
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/interactions/client/models/command.py", line 906, in wrapper
    return await coro(ctx, *args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/interactions/client/models/utils.py", line 66, in deferring_func
    return await task
  File "/Volumes/NTFS/LxBot-Yukimi-Project/lxbot-core/core/adapters/discord/__init__.py", line 41, in _
    await option["func"](self, ctx, **kwargs) # 回调函数
  File "/Volumes/NTFS/LxBot-Yukimi-Project/lxbot-core/modules/bilibili/main.py", line 18, in _
    await bot.reply(client, message_chain)
  File "/Volumes/NTFS/LxBot-Yukimi-Project/lxbot-core/core/adapters/discord/__init__.py", line 18, in reply
    await command_send(ctx, **MessageParser().parseArguments(content))
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/interactions/ext/files/files.py", line 356, in command_send
    await Inter_Request.create_interaction_response(
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/interactions/ext/files/files.py", line 63, in create_interaction_response
    return await self._req.request(
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/interactions/api/http/request.py", line 174, in request
    raise LibraryException(
interactions.api.error.LibraryException: An error occurred:
Unknown interaction, with code '10062' and severity '40'

JoinChang avatar Aug 18 '22 08:08 JoinChang

Again, the issue is likely because your code is blocking - ctx.defer can't help out with that.

For further help, please join the interactions.py Discord server and use the help channel.

AstreaTSS avatar Aug 18 '22 13:08 AstreaTSS

Reopening. Seems like this is an issue with autodefer not working as expected, though, as it seems to fail to defer at times.

AstreaTSS avatar Aug 18 '22 14:08 AstreaTSS

Heya. I think #1012 resolves this issue. Can you try to reproduce your bug on the latest version?

Damego avatar Nov 05 '22 15:11 Damego

Heya. I think #1012 resolves this issue. Can you try to reproduce your bug on the latest version?

Thanks, it works properly!

But it still randomly raise this error when processing time-consuming command, but @autodefer itself works properly. image image

JoinChang avatar Nov 05 '22 16:11 JoinChang

Heya. I think #1012 resolves this issue. Can you try to reproduce your bug on the latest version?

Thanks, it works properly!

But it still randomly raise this error when processing time-consuming command, but @autodefer itself works properly. image

Try setting the time after autodefer fires to smth lower, sometimes it is a bit slow

EepyElvyra avatar Nov 05 '22 16:11 EepyElvyra

Heya. I think #1012 resolves this issue. Can you try to reproduce your bug on the latest version?

Thanks, it works properly! But it still randomly raise this error when processing time-consuming command, but @autodefer itself works properly. image

Try setting the time after autodefer fires to smth lower, sometimes it is a bit slow

I tried lower delay params, and I'm didn't processing time-consuming command, but it still raised Unknown Interactions exception: image image

JoinChang avatar Nov 05 '22 16:11 JoinChang

Heya. I think #1012 resolves this issue. Can you try to reproduce your bug on the latest version?

Thanks, it works properly! But it still randomly raise this error when processing time-consuming command, but @autodefer itself works properly. image

Try setting the time after autodefer fires to smth lower, sometimes it is a bit slow

I tried lower delay params, but it still raised Unknown Interactions exception: image image

That's weird, @Toricane didn't you want to rewrite it?

EepyElvyra avatar Nov 05 '22 16:11 EepyElvyra

Resolved in v5

LordOfPolls avatar Apr 10 '23 12:04 LordOfPolls