interactions.py
interactions.py copied to clipboard
[BUG] Autodefer not always working
Describe the bug.
This happens when the command is not responded to for three seconds.

Example: https://autocode.com/autocode/threads/how-to-avoid-timeout-errors-when-responding-to-discord-interactions-tutorial-9f4b312c/
List the steps.
- Create a slash command and listen to it
- Create a time-consuming method
- Command is processing, but few seconds later, Discord returns a new interaction
- 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.
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.
To increase time limit up to 15 minutes you should defer your interaction via ctx.defer
To increase time limit up to 15 minutes you should defer your interaction via
ctx.defer
Thank you!
To increase time limit up to 15 minutes you should defer your interaction via
ctx.defer

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'
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.
Reopening. Seems like this is an issue with autodefer not working as expected, though, as it seems to fail to defer at times.
Heya. I think #1012 resolves this issue. Can you try to reproduce your bug on the latest version?
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.

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
@autodeferitself works properly.
Try setting the time after autodefer fires to smth lower, sometimes it is a bit slow
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
@autodeferitself works properly.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:

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
@autodeferitself works properly.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:
![]()
That's weird, @Toricane didn't you want to rewrite it?
Resolved in v5