From dc4ed438a5ba780fcaaf3fb46bbc603827d87bf2 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Mon, 12 Jun 2023 19:39:41 -0400 Subject: [PATCH] Fix plain username lookup for Guild.get_member_named Fix #9451 --- discord/ext/commands/converter.py | 10 ++++++++++ discord/guild.py | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/discord/ext/commands/converter.py b/discord/ext/commands/converter.py index 4cd8a353377c..30cea2a5ca9d 100644 --- a/discord/ext/commands/converter.py +++ b/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]: 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 @@ -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: diff --git a/discord/guild.py b/discord/guild.py index a37fb549f089..f7d1a5566589 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -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)