Skip to content

Commit e74fc60

Browse files
authored
Merge pull request #18 from hpenney2/master
Use fetch_member instead of get_member for auto-converting
2 parents e5b4311 + 1974195 commit e74fc60

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

discord_slash/client.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from . import http
66
from . import model
77
from .utils import manage_commands
8+
from inspect import iscoroutinefunction
89

910

1011
class SlashCommand:
@@ -231,7 +232,7 @@ def wrapper(cmd):
231232
return cmd
232233
return wrapper
233234

234-
def process_options(self, guild: discord.Guild, options: list, auto_convert: dict) -> list:
235+
async def process_options(self, guild: discord.Guild, options: list, auto_convert: dict) -> list:
235236
"""
236237
Processes Role, User, and Channel option types to discord.py's models.
237238
@@ -248,7 +249,7 @@ def process_options(self, guild: discord.Guild, options: list, auto_convert: dic
248249
return [x["value"] for x in options]
249250
if not auto_convert:
250251
return [x["value"] for x in options]
251-
converters = [guild.get_member, guild.get_channel, guild.get_role]
252+
converters = [guild.fetch_member, guild.get_channel, guild.get_role]
252253
types = {
253254
"user": 0,
254255
"USER": 0,
@@ -273,7 +274,9 @@ def process_options(self, guild: discord.Guild, options: list, auto_convert: dic
273274
to_return.append(selected["value"])
274275
continue
275276
loaded_converter = converters[types[auto_convert[selected["name"]]]]
276-
to_return.append(loaded_converter(int(selected["value"])))
277+
to_return.append(await loaded_converter(int(selected["value"]))) \
278+
if iscoroutinefunction(loaded_converter) else \
279+
to_return.append(loaded_converter(int(selected["value"])))
277280
return to_return
278281

279282
async def on_socket_response(self, msg):
@@ -296,7 +299,7 @@ async def on_socket_response(self, msg):
296299
return
297300
if selected_cmd["has_subcommands"]:
298301
return await self.handle_subcommand(ctx, to_use)
299-
args = self.process_options(ctx.guild, to_use["data"]["options"], selected_cmd["auto_convert"]) \
302+
args = await self.process_options(ctx.guild, to_use["data"]["options"], selected_cmd["auto_convert"]) \
300303
if "options" in to_use["data"] else []
301304
self.logger.debug(f"Command {to_use['data']['name']} invoked.")
302305
await selected_cmd["func"](ctx, *args)

0 commit comments

Comments
 (0)