diff --git a/revolt/ext/commands/context.py b/revolt/ext/commands/context.py index 4dc13b3..2a9bade 100755 --- a/revolt/ext/commands/context.py +++ b/revolt/ext/commands/context.py @@ -13,7 +13,7 @@ __all__ = ( class Context: """Stores metadata the commands execution. - + Parameters ----------- command: Optional[:class:`Command`] @@ -22,16 +22,28 @@ class Context: The command name that was used, this can be an alias, the commands name or a command that doesnt exist message: :class:`Message` The message that was sent to invoke the command + channel: :class:`Messageable` + The channel the command was invoked in + server: :class:`Server` + The server the command was invoked in + author: Union[:class:`Member`, :class:`User`] + The user or member that invoked the commad, will be :class:`User` in DMs + args: list[:class:`str`] + The arguments being passed to the command """ - __slots__ = ("command", "invoked_with", "message") + __slots__ = ("command", "invoked_with", "args", "message", "server", "channel", "author") - def __init__(self, command: Optional[Command], invoked_with: str, message: revolt.Message): + def __init__(self, command: Optional[Command], invoked_with: str, args: list[str], message: revolt.Message): self.command = command self.invoked_with = invoked_with + self.args = args self.message = message + self.server = message.server + self.channel = message.channel + self.author = message.author - async def invoke(self, args: list[str]) -> Any: - """Invokes the command, this is equal to `await context.command.invoke(context, args)`. + async def invoke(self) -> Any: + """Invokes the command, this is equal to `await command.invoke(context, context.args)`. .. note:: If the command is `None`, this function will do nothing. @@ -41,7 +53,7 @@ class Context: The args being passed to the command """ if command := self.command: - return await command.invoke(self, args) + return await command.invoke(self, self.args) @copy_doc(revolt.Messageable.send) async def send(self, content: Optional[str] = None, *, embeds: Optional[list[revolt.Embed]] = None, embed: Optional[revolt.Embed] = None, attachments: Optional[list[revolt.File]] = None) -> revolt.Message: diff --git a/revolt/ext/commands/mixin.py b/revolt/ext/commands/mixin.py index 5a8a8ab..0e16409 100755 --- a/revolt/ext/commands/mixin.py +++ b/revolt/ext/commands/mixin.py @@ -172,12 +172,12 @@ class CommandsMixin(metaclass=CommandsMeta): try: command = self.get_command(command_name) except KeyError: - return self.dispatch("command_error", Context(None, command_name, message), CommandNotFound(command_name)) + return self.dispatch("command_error", Context(None, command_name, args, message), CommandNotFound(command_name)) - context = self.get_context(message)(command, command_name, message) + context = self.get_context(message)(command, command_name, args, message) try: - return await context.invoke(args) + return await context.invoke() except Exception as e: self.dispatch("command_error", context, e)