diff options
| author | Rapptz <[email protected]> | 2016-04-29 08:45:12 -0400 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2016-04-29 08:45:12 -0400 |
| commit | 7f09acf871a7fbaa1de9b8509a24957a5894421d (patch) | |
| tree | 86240ee6004a0b28dd45ae29bda98c347d8f3011 | |
| parent | Simplify User.display_name a bit. (diff) | |
| download | discord.py-7f09acf871a7fbaa1de9b8509a24957a5894421d.tar.xz discord.py-7f09acf871a7fbaa1de9b8509a24957a5894421d.zip | |
[commands] Allow role mentions to work with discord.Role params.
This also fixes the Member regex to support the new <@!user_id> syntax
and allows colours to have a leading # before the number.
| -rw-r--r-- | discord/ext/commands/core.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py index cf065873..bc095375 100644 --- a/discord/ext/commands/core.py +++ b/discord/ext/commands/core.py @@ -155,7 +155,7 @@ class Command: return result def _convert_member(self, bot, message, argument): - match = re.match(r'<@([0-9]+)>$', argument) + match = re.match(r'<@!?([0-9]+)>$', argument) server = message.server result = None if match is None: @@ -202,6 +202,8 @@ class Command: def _convert_colour(self, bot, message, argument): arg = argument.replace('0x', '').lower() + if arg[0] == '#': + arg = arg[1:] try: value = int(arg, base=16) return discord.Colour(value=value) @@ -216,7 +218,9 @@ class Command: if not server: raise NoPrivateMessage() - result = discord.utils.get(server.roles, name=argument) + match = re.match(r'<@&([0-9]+)>$', argument) + params = dict(id=match.group(1)) if match else dict(name=argument) + result = discord.utils.get(server.roles, **params) if result is None: raise BadArgument('Role "{}" not found.'.format(argument)) return result |