Skip to content

Commit e5157b8

Browse files
committed
Fixed #97 by adding temporary auto_convert
1 parent 77cc755 commit e5157b8

File tree

1 file changed

+35
-7
lines changed

1 file changed

+35
-7
lines changed

discord_slash/client.py

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,8 @@ def wrapper(cmd):
603603

604604
return wrapper
605605

606-
async def process_options(self, guild: discord.Guild, options: list, connector: dict) -> dict:
606+
async def process_options(self, guild: discord.Guild, options: list, connector: dict,
607+
temporary_auto_convert: dict = None) -> dict:
607608
"""
608609
Processes Role, User, and Channel option types to discord.py's models.
609610
@@ -612,6 +613,7 @@ async def process_options(self, guild: discord.Guild, options: list, connector:
612613
:param options: Dict of options.
613614
:type options: list
614615
:param connector: Kwarg connector.
616+
:param temporary_auto_convert: Temporary parameter, use this if options doesn't have ``type`` keyword.
615617
:return: Union[list, dict]
616618
"""
617619

@@ -649,6 +651,12 @@ async def process_options(self, guild: discord.Guild, options: list, connector:
649651

650652
for x in options:
651653
processed = None # This isn't the best way, but we should to reduce duplicate lines.
654+
655+
# This is to temporarily fix Issue #97, that on Android device
656+
# does not give option type from API.
657+
if "type" not in x:
658+
x["type"] = temporary_auto_convert[x["name"]]
659+
652660
if x["type"] not in types:
653661
processed = x["value"]
654662
else:
@@ -731,8 +739,14 @@ async def on_socket_response(self, msg):
731739
if "value" not in x:
732740
return await self.handle_subcommand(ctx, to_use)
733741

734-
args = await self.process_options(ctx.guild, to_use["data"]["options"], selected_cmd.connector) \
735-
if "options" in to_use["data"] else []
742+
# This is to temporarily fix Issue #97, that on Android device
743+
# does not give option type from API.
744+
temporary_auto_convert = {}
745+
for x in selected_cmd.options:
746+
temporary_auto_convert[x["name"]] = x["type"]
747+
748+
args = await self.process_options(ctx.guild, to_use["data"]["options"], selected_cmd.connector, temporary_auto_convert) \
749+
if "options" in to_use["data"] else {}
736750

737751
self._discord.dispatch("slash_command", ctx)
738752

@@ -764,14 +778,28 @@ async def handle_subcommand(self, ctx: context.SlashContext, data: dict):
764778
return
765779
ctx.subcommand_group = sub_group
766780
selected = base[sub_name][sub_group]
767-
args = await self.process_options(ctx.guild, x["options"], selected.connector) \
768-
if "options" in x else []
781+
782+
# This is to temporarily fix Issue #97, that on Android device
783+
# does not give option type from API.
784+
temporary_auto_convert = {}
785+
for n in selected.options:
786+
temporary_auto_convert[n["name"]] = n["type"]
787+
788+
args = await self.process_options(ctx.guild, x["options"], selected.connector, temporary_auto_convert) \
789+
if "options" in x else {}
769790
self._discord.dispatch("slash_command", ctx)
770791
await self.invoke_command(selected, ctx, args)
771792
return
772793
selected = base[sub_name]
773-
args = await self.process_options(ctx.guild, sub_opts, selected.connector) \
774-
if "options" in sub else []
794+
795+
# This is to temporarily fix Issue #97, that on Android device
796+
# does not give option type from API.
797+
temporary_auto_convert = {}
798+
for n in selected.options:
799+
temporary_auto_convert[n["name"]] = n["type"]
800+
801+
args = await self.process_options(ctx.guild, sub_opts, selected.connector, temporary_auto_convert) \
802+
if "options" in sub else {}
775803
self._discord.dispatch("slash_command", ctx)
776804
await self.invoke_command(selected, ctx, args)
777805

0 commit comments

Comments
 (0)