[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
This commit is contained in:
Rapptz
2026-01-11 08:02:50 -05:00
parent 1df81fea52
commit b9b21ca270

View File

@@ -259,6 +259,7 @@ class Context(discord.abc.Messageable, Generic[BotT]):
bot: BotT = interaction.client bot: BotT = interaction.client
data: ApplicationCommandInteractionData = interaction.data # type: ignore data: ApplicationCommandInteractionData = interaction.data # type: ignore
type_ = data.get('type', 1)
if interaction.message is None: if interaction.message is None:
synthetic_payload = { synthetic_payload = {
'id': interaction.id, 'id': interaction.id,
@@ -268,7 +269,7 @@ class Context(discord.abc.Messageable, Generic[BotT]):
'tts': False, 'tts': False,
'pinned': False, 'pinned': False,
'edited_timestamp': None, '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, 'flags': 64,
'content': '', 'content': '',
'mentions': [], 'mentions': [],
@@ -288,7 +289,7 @@ class Context(discord.abc.Messageable, Generic[BotT]):
else: else:
message = interaction.message 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( ctx = cls(
message=message, message=message,
bot=bot, bot=bot,