mirror of
https://github.com/danbulant/discord.js
synced 2026-05-24 12:35:53 +00:00
Add resolveUserID and improve other resolutions
This commit is contained in:
parent
ab7682f921
commit
bbddfef7f6
1 changed files with 21 additions and 15 deletions
|
|
@ -38,18 +38,24 @@ class ClientDataResolver {
|
|||
* @returns {?User}
|
||||
*/
|
||||
resolveUser(user) {
|
||||
if (user instanceof User) {
|
||||
return user;
|
||||
} else if (typeof user === 'string') {
|
||||
return this.client.users.get(user);
|
||||
} else if (user instanceof Message) {
|
||||
return user.author;
|
||||
} else if (user instanceof Guild) {
|
||||
return user.owner;
|
||||
} else if (user instanceof GuildMember) {
|
||||
return user.user;
|
||||
}
|
||||
if (user instanceof User) return user;
|
||||
if (typeof user === 'string') return this.client.users.get(user) || null;
|
||||
if (user instanceof GuildMember) return user.user;
|
||||
if (user instanceof Message) return user.author;
|
||||
if (user instanceof Guild) return user.owner;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves a UserResolvable to a user ID string
|
||||
* @param {UserResolvable} user The UserResolvable to identify
|
||||
* @returns {?string}
|
||||
*/
|
||||
resolveUserID(user) {
|
||||
if (user instanceof User || user instanceof GuildMember) return user.id;
|
||||
if (typeof user === 'string') return user || null;
|
||||
if (user instanceof Message) return user.author.id;
|
||||
if (user instanceof Guild) return user.owner.id;
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -66,7 +72,7 @@ class ClientDataResolver {
|
|||
*/
|
||||
resolveGuild(guild) {
|
||||
if (guild instanceof Guild) return guild;
|
||||
if (typeof guild === 'string') return this.client.guilds.get(guild);
|
||||
if (typeof guild === 'string') return this.client.guilds.get(guild) || null;
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -90,7 +96,7 @@ class ClientDataResolver {
|
|||
user = this.resolveUser(user);
|
||||
if (!guild || !user) return null;
|
||||
|
||||
return guild.members.get(user.id);
|
||||
return guild.members.get(user.id) || null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -127,8 +133,8 @@ class ClientDataResolver {
|
|||
resolveChannel(channel) {
|
||||
if (channel instanceof Channel) return channel;
|
||||
if (channel instanceof Message) return channel.channel;
|
||||
if (channel instanceof Guild) return channel.channels.get(channel.id);
|
||||
if (typeof channel === 'string') return this.client.channels.get(channel.id);
|
||||
if (channel instanceof Guild) return channel.channels.get(channel.id) || null;
|
||||
if (typeof channel === 'string') return this.client.channels.get(channel.id) || null;
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue