Browse Source

Fix plain username lookup for Guild.get_member_named

Fix #9451
pull/9454/head
Rapptz 2 years ago
parent
commit
dc4ed438a5
  1. 10
      discord/ext/commands/converter.py
  2. 5
      discord/guild.py

10
discord/ext/commands/converter.py

@ -207,6 +207,11 @@ class MemberConverter(IDConverter[discord.Member]):
async def query_member_named(self, guild: discord.Guild, argument: str) -> Optional[discord.Member]: async def query_member_named(self, guild: discord.Guild, argument: str) -> Optional[discord.Member]:
cache = guild._state.member_cache_flags.joined cache = guild._state.member_cache_flags.joined
username, _, discriminator = argument.rpartition('#') username, _, discriminator = argument.rpartition('#')
# If # isn't found then "discriminator" actually has the username
if not username:
discriminator, username = username, discriminator
if discriminator == '0' or (len(discriminator) == 4 and discriminator.isdigit()): if discriminator == '0' or (len(discriminator) == 4 and discriminator.isdigit()):
lookup = username lookup = username
predicate = lambda m: m.name == username and m.discriminator == discriminator predicate = lambda m: m.name == username and m.discriminator == discriminator
@ -316,6 +321,11 @@ class UserConverter(IDConverter[discord.User]):
return result # type: ignore return result # type: ignore
username, _, discriminator = argument.rpartition('#') username, _, discriminator = argument.rpartition('#')
# If # isn't found then "discriminator" actually has the username
if not username:
discriminator, username = username, discriminator
if discriminator == '0' or (len(discriminator) == 4 and discriminator.isdigit()): if discriminator == '0' or (len(discriminator) == 4 and discriminator.isdigit()):
predicate = lambda u: u.name == username and u.discriminator == discriminator predicate = lambda u: u.name == username and u.discriminator == discriminator
else: else:

5
discord/guild.py

@ -1104,6 +1104,11 @@ class Guild(Hashable):
members = self.members members = self.members
username, _, discriminator = name.rpartition('#') username, _, discriminator = name.rpartition('#')
# If # isn't found then "discriminator" actually has the username
if not username:
discriminator, username = username, discriminator
if discriminator == '0' or (len(discriminator) == 4 and discriminator.isdigit()): if discriminator == '0' or (len(discriminator) == 4 and discriminator.isdigit()):
return utils.find(lambda m: m.name == username and m.discriminator == discriminator, members) return utils.find(lambda m: m.name == username and m.discriminator == discriminator, members)

Loading…
Cancel
Save