[commands] Fetch user if an ID is passed and cache lookup fails.

This commit is contained in:
Rapptz 2020-11-23 06:22:23 -05:00
parent c8954906cb
commit 0456458ad1

View File

@ -206,6 +206,10 @@ class UserConverter(IDConverter):
.. versionchanged:: 1.5
Raise :exc:`.UserNotFound` instead of generic :exc:`.BadArgument`
.. versionchanged:: 1.6
This converter now lazily fetches users from the HTTP APIs if an ID is passed
and it's not available in cache.
"""
async def convert(self, ctx, argument):
match = self._get_id_match(argument) or re.match(r'<@!?([0-9]+)>$', argument)
@ -215,7 +219,14 @@ class UserConverter(IDConverter):
if match is not None:
user_id = int(match.group(1))
result = ctx.bot.get_user(user_id) or _utils_get(ctx.message.mentions, id=user_id)
else:
if result is None:
try:
result = await ctx.bot.fetch_user(user_id)
except discord.HTTPException:
raise UserNotFound(argument) from None
return result
arg = argument
# Remove the '@' character if this is the first character from the argument