Skip to content

Commit

Permalink
Fix plain username lookup for Guild.get_member_named
Browse files Browse the repository at this point in the history
Fix #9451
  • Loading branch information
Rapptz committed Jun 12, 2023
1 parent 0c6a2fc commit dc4ed43
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
10 changes: 10 additions & 0 deletions discord/ext/commands/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ class MemberConverter(IDConverter[discord.Member]):
async def query_member_named(self, guild: discord.Guild, argument: str) -> Optional[discord.Member]:
cache = guild._state.member_cache_flags.joined
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()):
lookup = username
predicate = lambda m: m.name == username and m.discriminator == discriminator
Expand Down Expand Up @@ -316,6 +321,11 @@ async def convert(self, ctx: Context[BotT], argument: str) -> discord.User:
return result # type: ignore

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()):
predicate = lambda u: u.name == username and u.discriminator == discriminator
else:
Expand Down
5 changes: 5 additions & 0 deletions discord/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,11 @@ def get_member_named(self, name: str, /) -> Optional[Member]:
members = self.members

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()):
return utils.find(lambda m: m.name == username and m.discriminator == discriminator, members)

Expand Down

0 comments on commit dc4ed43

Please sign in to comment.