Skip to content

Commit

Permalink
Handle mentionable in invoke
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeWithSwastik committed Aug 31, 2021
1 parent 7e8d99a commit af8ff45
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
11 changes: 8 additions & 3 deletions discord/app/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from ..message import Message
from .context import InteractionContext
from ..utils import find, get_or_fetch

from ..errors import NotFound

class ApplicationCommand:
def __repr__(self):
Expand Down Expand Up @@ -88,7 +88,7 @@ def __init__(self, func: Callable, *args, **kwargs) -> None:
for a, o in options.items():
o = o.annotation
if not isinstance(o, Option):
o = Option(o, 'No description provided')
o = Option(o, "No description provided")
if o.name is None:
o.name = a
self.options.append(o)
Expand Down Expand Up @@ -128,7 +128,12 @@ async def invoke(self, interaction) -> None:
):
arg = await get_or_fetch(ctx.guild, op.input_type.name, int(arg))

# TODO: Add discord.Mentionable
elif op.input_type == SlashCommandOptionType.mentionable:
try:
arg = await get_or_fetch(ctx.guild, "member", int(arg))
except NotFound:
arg = await get_or_fetch(ctx.guild, "role", int(arg))

final_args.append(arg)

await self.callback(ctx, *final_args)
Expand Down
3 changes: 2 additions & 1 deletion discord/app/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from ..interactions import Interaction
from ..utils import cached_property


class InteractionContext:
def __init__(self, interaction: Interaction):
self.interaction = interaction
Expand Down Expand Up @@ -59,4 +60,4 @@ def respond(self):

@property
def defer(self):
return self.interaction.response.defer
return self.interaction.response.defer

0 comments on commit af8ff45

Please sign in to comment.