Skip to content

Commit 69a614a

Browse files
authored
Check if the target is a system or bot message (#1236)
* Check if the target is a system or bot message * Convert author ID to int only once
1 parent 3a4f0da commit 69a614a

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

discord/commands/core.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
from ..role import Role
5353
from ..object import Object
5454
from ..channel import _guild_channel_factory
55-
from ..enums import ChannelType, SlashCommandOptionType
55+
from ..enums import ChannelType, MessageType, SlashCommandOptionType, try_enum
5656
from ..errors import (
5757
ClientException,
5858
ValidationError,
@@ -1418,7 +1418,18 @@ async def _invoke(self, ctx: ApplicationContext):
14181418
message = v
14191419
channel = ctx.interaction._state.get_channel(int(message["channel_id"]))
14201420
if channel is None:
1421-
data = await ctx.interaction._state.http.start_private_message(int(message["author"]["id"]))
1421+
author_id = int(message["author"]["id"])
1422+
self_or_system_message: bool = (
1423+
ctx.bot.user.id == author_id
1424+
or try_enum(MessageType, message["type"]) not in (
1425+
MessageType.default,
1426+
MessageType.reply,
1427+
MessageType.application_command,
1428+
MessageType.thread_starter_message,
1429+
)
1430+
)
1431+
user_id = ctx.author.id if self_or_system_message else author_id
1432+
data = await ctx.interaction._state.http.start_private_message(user_id)
14221433
channel = ctx.interaction._state.add_dm_channel(data)
14231434

14241435
target = Message(state=ctx.interaction._state, channel=channel, data=message)

0 commit comments

Comments
 (0)