Fixes #2
parent
6a95ad10e5
commit
b4ff1ce805
|
@ -48,32 +48,8 @@ export default class Util {
|
|||
}
|
||||
|
||||
public resolveMember(message: Message, search: string, guild: Guild): Member | undefined {
|
||||
try {
|
||||
// Name, Mention, or ID
|
||||
let member = guild.members.find((mem) => mem.user.id === message.mentions[0].id || `${mem.user.username}#${mem.user.discriminator}` === search || mem.user.id === search || mem.user.username === search || mem.user.username.startsWith(search) || mem.user.username.toLowerCase() === search.toLowerCase() || mem.user.username.toLowerCase().startsWith(search.toLowerCase()));
|
||||
// Nickname
|
||||
// eslint-disable-next-line no-mixed-operators
|
||||
if (!member) {
|
||||
member = guild.members.find((mem) => mem.nick && (mem.nick === search || mem.nick.startsWith(search) || mem.nick.toLowerCase() === search.toLowerCase() || mem.nick.toLowerCase().startsWith(search.toLowerCase())));
|
||||
}
|
||||
if (search.split(' ').length > 1 && !member) {
|
||||
let nSearch = search.split(' ');
|
||||
while (!member && nSearch.length > 0) {
|
||||
nSearch = nSearch.slice(0, nSearch.length - 1);
|
||||
// Name, Mention, or ID
|
||||
member = guild.members.find((mem) => mem.user.id === message.mentions[0].id || `${mem.user.username}#${mem.user.discriminator}` === search || mem.user.id === search || mem.user.username === search || mem.user.username.startsWith(search) || mem.user.username.toLowerCase() === search.toLowerCase() || mem.user.username.toLowerCase().startsWith(search.toLowerCase()));
|
||||
// Nickname
|
||||
// eslint-disable-next-line no-mixed-operators
|
||||
if (!member) {
|
||||
member = guild.members.find((mem) => mem.nick && (mem.nick === search || mem.nick.startsWith(search) || mem.nick.toLowerCase() === search.toLowerCase() || mem.nick.toLowerCase().startsWith(search.toLowerCase())));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!member) return undefined;
|
||||
return member;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
return members.find((m) => m.mention.replace('!', '') === query.replace('!', '') || `${m.username}#${m.discriminator}` === query || m.username === query || m.id === query || m.nick === query) // Exact match for mention, username+discrim, username and user ID
|
||||
|| members.find((m) => `${m.username.toLowerCase()}#${m.discriminator}` === query.toLowerCase() || m.username.toLowerCase() === query.toLowerCase() || (m.nick && m.nick.toLowerCase() === query.toLowerCase())) // Case insensitive match for username+discrim, username
|
||||
}
|
||||
|
||||
public async handleError(error: Error, message?: Message, command?: Command): Promise<void> {
|
||||
|
|
Loading…
Reference in New Issue