aboutsummaryrefslogtreecommitdiff
path: root/discord/ext
diff options
context:
space:
mode:
authorMrKomodoDragon <[email protected]>2021-04-14 19:09:40 -0700
committerGitHub <[email protected]>2021-04-14 22:09:40 -0400
commited3c141f5e2b1238eb4168229cb52ef5c756c117 (patch)
tree35a0db0a103b9558a2124e91019f9c727b59370c /discord/ext
parentAdd note to member docs about Spotify limitation (diff)
downloaddiscord.py-ed3c141f5e2b1238eb4168229cb52ef5c756c117.tar.xz
discord.py-ed3c141f5e2b1238eb4168229cb52ef5c756c117.zip
[commands] Add `clean_prefix` attribute to commands.Context
Diffstat (limited to 'discord/ext')
-rw-r--r--discord/ext/commands/context.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/discord/ext/commands/context.py b/discord/ext/commands/context.py
index cbd28597..3b938469 100644
--- a/discord/ext/commands/context.py
+++ b/discord/ext/commands/context.py
@@ -207,6 +207,20 @@ class Context(discord.abc.Messageable):
return self.channel
@property
+ def clean_prefix(self):
+ """:class:`str`: The cleaned up invoke prefix. i.e. mentions are ``@name`` instead of ``<@id>``.
+
+ .. versionadded:: 2.0
+ """
+ user = self.guild.me if self.guild else self.bot.user
+ # this breaks if the prefix mention is not the bot itself but I
+ # consider this to be an *incredibly* strange use case. I'd rather go
+ # for this common use case rather than waste performance for the
+ # odd one.
+ pattern = re.compile(r"<@!?%s>" % user.id)
+ return pattern.sub("@%s" % user.display_name.replace('\\', r'\\'), self.prefix)
+
+ @property
def cog(self):
"""Optional[:class:`.Cog`]: Returns the cog associated with this context's command. None if it does not exist."""