diff --git a/discord/ext/commands/context.py b/discord/ext/commands/context.py index 3cf851c6..a80b4f86 100644 --- a/discord/ext/commands/context.py +++ b/discord/ext/commands/context.py @@ -26,6 +26,7 @@ DEALINGS IN THE SOFTWARE. import discord.abc import discord.utils +import re class Context(discord.abc.Messageable): r"""Represents the context in which a command is being invoked under. @@ -50,8 +51,6 @@ class Context(discord.abc.Messageable): A dictionary of transformed arguments that were passed into the command. Similar to :attr:`args`\, if this is accessed in the :func:`on_command_error` event then this dict could be incomplete. - prefix: :class:`str` - The prefix that was used to invoke the command. command: :class:`Command` The command that is being invoked currently. invoked_with: :class:`str` @@ -75,7 +74,7 @@ class Context(discord.abc.Messageable): self.bot = attrs.pop('bot', None) self.args = attrs.pop('args', []) self.kwargs = attrs.pop('kwargs', {}) - self.prefix = attrs.pop('prefix') + self._prefix = attrs.pop('prefix') self.command = attrs.pop('command', None) self.view = attrs.pop('view', None) self.invoked_with = attrs.pop('invoked_with', None) @@ -84,6 +83,13 @@ class Context(discord.abc.Messageable): self.command_failed = attrs.pop('command_failed', False) self._state = self.message._state + @property + def prefix(self): + """:class:`str`: The cleaned up invoke prefix. i.e. mentions are ``@name`` instead of ``<@id>``.""" + user = self.guild.me if self.guild else self.bot.user + pattern = re.compile(r"<@!?%s>" % user.id) + return pattern.sub("@%s" % user.display_name.replace('\\', r'\\'), self._prefix) + async def invoke(self, *args, **kwargs): r"""|coro|