Browse Source

[commands] Fix Context.from_interaction derived Message.type

The previous Message.type when accessed from Context would be an
unknown enum type because the enum was double nested when the proper
type expected by the synthetic payload was an int not an enum.

Fix #10382
pull/10383/head
Rapptz 6 months ago
parent
commit
b9b21ca270
  1. 5
      discord/ext/commands/context.py

5
discord/ext/commands/context.py

@ -259,6 +259,7 @@ class Context(discord.abc.Messageable, Generic[BotT]):
bot: BotT = interaction.client
data: ApplicationCommandInteractionData = interaction.data # type: ignore
type_ = data.get('type', 1)
if interaction.message is None:
synthetic_payload = {
'id': interaction.id,
@ -268,7 +269,7 @@ class Context(discord.abc.Messageable, Generic[BotT]):
'tts': False,
'pinned': False,
'edited_timestamp': None,
'type': MessageType.chat_input_command if data.get('type', 1) == 1 else MessageType.context_menu_command,
'type': MessageType.chat_input_command.value if type_ == 1 else MessageType.context_menu_command.value,
'flags': 64,
'content': '',
'mentions': [],
@ -288,7 +289,7 @@ class Context(discord.abc.Messageable, Generic[BotT]):
else:
message = interaction.message
prefix = '/' if data.get('type', 1) == 1 else '\u200b' # Mock the prefix
prefix = '/' if type_ == 1 else '\u200b' # Mock the prefix
ctx = cls(
message=message,
bot=bot,

Loading…
Cancel
Save