resolveUser: return null if the passed value is not a valid id

This commit is contained in:
Dragory 2020-08-09 20:10:03 +03:00
parent 5215dd0738
commit a641312853
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
6 changed files with 21 additions and 4 deletions

View file

@ -972,8 +972,7 @@ export function resolveUserId(bot: Client, value: string) {
}
// Just a user ID?
const idMatch = value.match(/^\d+$/);
if (idMatch) {
if (isValidSnowflake(value)) {
return value;
}
@ -1000,12 +999,12 @@ export async function resolveUser<T>(bot, value) {
return new UnknownUser();
}
// If we have the user cached, return that directly
const userId = resolveUserId(bot, value);
if (!userId) {
return new UnknownUser({ id: userId });
return null;
}
// If we have the user cached, return that directly
if (bot.users.has(userId)) {
return bot.users.get(userId);
}