Closed
Description
Library Version
5.8.0
Describe the Bug
When calling a hybrid slash command from a DM channel as a prefixed command, an error occurs while trying to create a HybridContext from a PrefixedContext, due to ctx.channel
being None
.
Steps to Reproduce
- Create a hybrid slash command, with
dm_permission = True
(True by default) - In a DM with the bot, invoke the command using the prefixed commands route (i.e. NOT using slash commands)
(Example, with traceback printout omitted)
Expected Results
The command should invoke normally.
Minimal Reproducible Code
from interactions import Client
from interactions.ext import hybrid_commands, prefixed_commands
client = Client()
prefixed_commands.setup(client)
hybrid_commands.setup(client)
@hybrid_commands.hybrid_slash_command(name="cmd1", description="broken in DMs")
async def cmd1(ctx: hybrid_commands.HybridContext):
# works fine in a guild, but breaks when called as a prefixedcommand in DM
await ctx.send("hybrid command")
@prefixed_commands.prefixed_command(name="cmd2")
async def cmd2(ctx: prefixed_commands.PrefixedContext):
await ctx.send("prefixed commands work")
client.start(token="YOUR_BOT_TOKEN")
Traceback
Traceback (most recent call last):
File "/**/venv/lib/python3.11/site-packages/interactions/ext/prefixed_commands/manager.py", line 336, in _dispatch_prefixed_commands
await command(context)
File "/**/venv/lib/python3.11/site-packages/interactions/ext/hybrid_commands/hybrid_slash.py", line 307, in __call__
new_ctx = context.client.hybrid.hybrid_context.from_prefixed_context(context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/**/venv/lib/python3.11/site-packages/interactions/ext/hybrid_commands/context.py", line 119, in from_prefixed_context
elif ctx.channel.type in {10, 11, 12}: # it's a thread
^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'type'
Checklist
- I have searched the open issues for duplicates.
- I have shown the entire traceback, if possible.
- I have removed my token from display, if visible.
- I have attempted to debug this myself, and I believe this issue is with the library
Additional Information
Setting up a PrefixedCommand
with the same setup results in no issues (see the example code). I'm not very familiar with the library's internals, but as I understand it, the following is happening to create this problem:
- We generate a
PrefixedContext
using the message invoking the command HybridContext
tries to accessPrefixedContext.channel
, which in turn tries to get theDMChannel
from the client cache- However, since the DMChannel is not cached,
.channel
is None - Accessing
.channel.type
then results in anAttributeError
I don't know if app permissions are inferred from a channel anywhere else in the library, but that might be the way to fixing this.
Metadata
Metadata
Assignees
Labels
No labels