aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2017-01-14 22:15:02 -0500
committerRapptz <[email protected]>2017-01-14 22:15:02 -0500
commit11b54d67c9ea8accfacd70971f8498ac2bd1b9dc (patch)
tree4c8cf747bcf84f79124a4232120bcf452af9a328
parentRemove _get_guild_id from Messageable ABC. (diff)
downloaddiscord.py-11b54d67c9ea8accfacd70971f8498ac2bd1b9dc.tar.xz
discord.py-11b54d67c9ea8accfacd70971f8498ac2bd1b9dc.zip
[commands] Change UserConverter to actually work with User, not Member.
-rw-r--r--discord/ext/commands/converter.py28
1 files changed, 27 insertions, 1 deletions
diff --git a/discord/ext/commands/converter.py b/discord/ext/commands/converter.py
index 7e54241f..4284fa59 100644
--- a/discord/ext/commands/converter.py
+++ b/discord/ext/commands/converter.py
@@ -101,7 +101,33 @@ class MemberConverter(IDConverter):
return result
-UserConverter = MemberConverter
+class UserConverter(IDConverter):
+ def convert(self):
+ match = self._get_id_match() or re.match(r'<@!?([0-9]+)>$', self.argument)
+ result = None
+ state = self.ctx._state
+
+ if match is not None:
+ user_id = int(match.group(1))
+ result = self.bot.get_user(user_id)
+ else:
+ arg = self.argument
+ # check for discriminator if it exists
+ if len(arg) > 5 and arg[-5] == '#':
+ discrim = arg[-4:]
+ name = arg[:-5]
+ predicate = lambda u: u.name == name and u.discriminator == discrim
+ result = discord.utils.find(predicate, state._users.values())
+ if result is not None:
+ return result
+
+ predicate = lambda u: u.name == arg
+ result = discord.utils.find(predicate, state._users.values())
+
+ if result is None:
+ raise BadArgument('User "{}" not found'.format(self.argument))
+
+ return result
class TextChannelConverter(IDConverter):
def convert(self):