Skip to content

Commit 5ba5058

Browse files
committed
Changed SlashContext.guild is ID when cannot get guild
1 parent 4c92953 commit 5ba5058

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

discord_slash/model.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class SlashContext:
2020
:ivar _discord: :class:`discord.ext.commands.Bot`
2121
:ivar logger: Logger instance.
2222
:ivar sent: Whether you sent the initial response.
23-
:ivar guild: :class:`discord.Guild` instance of the command message.
23+
:ivar guild: :class:`discord.Guild` instance or guild ID of the command message.
2424
:ivar author: :class:`discord.Member` instance or user ID representing author of the command message.
2525
:ivar channel: :class:`discord.TextChannel` instance or channel ID representing channel of the command message.
2626
"""
@@ -38,7 +38,7 @@ def __init__(self,
3838
self._discord = _discord
3939
self.logger = logger
4040
self.sent = False
41-
self.guild: discord.Guild = _discord.get_guild(int(_json["guild_id"]))
41+
self.guild: typing.Union[discord.Guild, int] = _discord.get_guild(int(_json["guild_id"]))
4242
self.author: typing.Union[discord.Member, int] = self.guild.get_member(int(_json["member"]["user"]["id"])) \
4343
if self.guild else None
4444
self.channel: typing.Union[discord.TextChannel, int] = self.guild.get_channel(int(_json["channel_id"])) \
@@ -47,6 +47,9 @@ def __init__(self,
4747
self.author = int(_json["member"]["user"]["id"])
4848
if not self.channel:
4949
self.channel = int(_json["channel_id"])
50+
if not self.guild:
51+
# Should be set after every others are set.
52+
self.guild = int(_json["guild_id"])
5053

5154
async def send(self,
5255
send_type: int = 4,

0 commit comments

Comments
 (0)