Skip to content

Commit b867088

Browse files
committed
Fixed no author when intent is off
1 parent 3b91595 commit b867088

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

discord_slash/model.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ class SlashContext:
2121
:ivar logger: Logger instance.
2222
:ivar sent: Whether you sent the initial response.
2323
:ivar guild: :class:`discord.Guild` instance of the command message.
24-
:ivar author: :class:`discord.Member` instance representing author of the command message.
25-
:ivar channel: :class:`discord.TextChannel` instance representing channel of the command message.
24+
:ivar author: :class:`discord.Member` instance or user ID representing author of the command message.
25+
:ivar channel: :class:`discord.TextChannel` instance or channel ID representing channel of the command message.
2626
"""
2727

2828
def __init__(self,
@@ -39,8 +39,14 @@ def __init__(self,
3939
self.logger = logger
4040
self.sent = False
4141
self.guild: discord.Guild = _discord.get_guild(int(_json["guild_id"]))
42-
self.author: discord.Member = self.guild.get_member(int(_json["member"]["user"]["id"])) if self.guild else None
43-
self.channel = self.guild.get_channel(int(_json["channel_id"])) if self.guild else None
42+
self.author: typing.Union[discord.Member, int] = self.guild.get_member(int(_json["member"]["user"]["id"])) \
43+
if self.guild else None
44+
self.channel: typing.Union[discord.TextChannel, int] = self.guild.get_channel(int(_json["channel_id"])) \
45+
if self.guild else None
46+
if not self.author:
47+
self.author = int(_json["member"]["user"]["id"])
48+
if not self.channel:
49+
self.channel = int(_json["channel_id"])
4450

4551
async def send(self,
4652
send_type: int = 4,

0 commit comments

Comments
 (0)