Skip to content

Commit 42f9081

Browse files
authored
Merge pull request #36 from 4surix/master
Fix error raised when value ctx.guild is type int
2 parents 20359fe + 1a7d7a6 commit 42f9081

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

discord_slash/client.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,13 @@ async def process_options(self, guild: discord.Guild, options: list, auto_conver
413413
if not guild:
414414
self.logger.info("This command invoke is missing guild. Skipping option process.")
415415
return [x["value"] for x in options]
416+
417+
if not isinstance(guild, discord.Guild):
418+
return [x["value"] for x in options]
419+
416420
if not auto_convert:
417421
return [x["value"] for x in options]
422+
418423
converters = [
419424
[guild.get_member, guild.fetch_member],
420425
guild.get_channel,
@@ -471,21 +476,37 @@ async def on_socket_response(self, msg):
471476
"""
472477
if msg["t"] != "INTERACTION_CREATE":
473478
return
479+
474480
to_use = msg["d"]
481+
475482
if to_use["data"]["name"] in self.commands.keys():
483+
476484
ctx = model.SlashContext(self.req, to_use, self._discord, self.logger)
477485
cmd_name = to_use["data"]["name"]
486+
478487
if cmd_name not in self.commands.keys() and cmd_name in self.subcommands.keys():
479488
return await self.handle_subcommand(ctx, to_use)
489+
480490
selected_cmd = self.commands[to_use["data"]["name"]]
491+
481492
if selected_cmd.allowed_guild_ids:
482-
if ctx.guild.id not in selected_cmd.allowed_guild_ids:
493+
guild_id = (
494+
ctx.guild.id if isinstance(ctx.guild, discord.Guild)
495+
else
496+
ctx.guild
497+
)
498+
499+
if guild_id not in selected_cmd.allowed_guild_ids:
483500
return
501+
484502
if selected_cmd.has_subcommands:
485503
return await self.handle_subcommand(ctx, to_use)
504+
486505
args = await self.process_options(ctx.guild, to_use["data"]["options"], selected_cmd.auto_convert) \
487506
if "options" in to_use["data"] else []
507+
488508
self._discord.dispatch("slash_command", ctx)
509+
489510
try:
490511
await selected_cmd.invoke(ctx, *args)
491512
except Exception as ex:

0 commit comments

Comments
 (0)