mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
fix(Resolvables): valid resolvables throw error when uncached (#5495)
Co-authored-by: Sugden <28943913+NotSugden@users.noreply.github.com>
This commit is contained in:
@@ -51,13 +51,13 @@ class GuildEmojiManager extends BaseGuildEmojiManager {
|
||||
if (roles) {
|
||||
data.roles = [];
|
||||
for (let role of roles instanceof Collection ? roles.values() : roles) {
|
||||
role = this.guild.roles.resolve(role);
|
||||
if (!role) {
|
||||
const roleID = this.guild.roles.resolveID(role);
|
||||
if (!roleID) {
|
||||
return Promise.reject(
|
||||
new TypeError('INVALID_TYPE', 'options.roles', 'Array or Collection of Roles or Snowflakes', true),
|
||||
);
|
||||
}
|
||||
data.roles.push(role.id);
|
||||
data.roles.push(roleID);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ class GuildEmojiRoleManager {
|
||||
add(roleOrRoles) {
|
||||
if (roleOrRoles instanceof Collection) return this.add(roleOrRoles.keyArray());
|
||||
if (!Array.isArray(roleOrRoles)) return this.add([roleOrRoles]);
|
||||
roleOrRoles = roleOrRoles.map(r => this.guild.roles.resolve(r));
|
||||
roleOrRoles = roleOrRoles.map(r => this.guild.roles.resolveID(r));
|
||||
|
||||
if (roleOrRoles.includes(null)) {
|
||||
return Promise.reject(new TypeError('INVALID_TYPE', 'roles', 'Array or Collection of Roles or Snowflakes', true));
|
||||
|
||||
@@ -100,7 +100,7 @@ class GuildMemberRoleManager {
|
||||
*/
|
||||
async add(roleOrRoles, reason) {
|
||||
if (roleOrRoles instanceof Collection || Array.isArray(roleOrRoles)) {
|
||||
roleOrRoles = roleOrRoles.map(r => this.guild.roles.resolve(r));
|
||||
roleOrRoles = roleOrRoles.map(r => this.guild.roles.resolveID(r));
|
||||
if (roleOrRoles.includes(null)) {
|
||||
throw new TypeError('INVALID_TYPE', 'roles', 'Array or Collection of Roles or Snowflakes', true);
|
||||
}
|
||||
@@ -108,15 +108,15 @@ class GuildMemberRoleManager {
|
||||
const newRoles = [...new Set(roleOrRoles.concat(...this._roles.values()))];
|
||||
return this.set(newRoles, reason);
|
||||
} else {
|
||||
roleOrRoles = this.guild.roles.resolve(roleOrRoles);
|
||||
if (roleOrRoles === null) {
|
||||
const roleID = this.guild.roles.resolveID(roleOrRoles);
|
||||
if (roleID === null) {
|
||||
throw new TypeError('INVALID_TYPE', 'roles', 'Role, Snowflake or Array or Collection of Roles or Snowflakes');
|
||||
}
|
||||
|
||||
await this.client.api.guilds[this.guild.id].members[this.member.id].roles[roleOrRoles.id].put({ reason });
|
||||
await this.client.api.guilds[this.guild.id].members[this.member.id].roles[roleID].put({ reason });
|
||||
|
||||
const clone = this.member._clone();
|
||||
clone._roles = [...this._roles.keys(), roleOrRoles.id];
|
||||
clone._roles = [...this._roles.keys(), roleID];
|
||||
return clone;
|
||||
}
|
||||
}
|
||||
@@ -129,7 +129,7 @@ class GuildMemberRoleManager {
|
||||
*/
|
||||
async remove(roleOrRoles, reason) {
|
||||
if (roleOrRoles instanceof Collection || Array.isArray(roleOrRoles)) {
|
||||
roleOrRoles = roleOrRoles.map(r => this.guild.roles.resolve(r));
|
||||
roleOrRoles = roleOrRoles.map(r => this.guild.roles.resolveID(r));
|
||||
if (roleOrRoles.includes(null)) {
|
||||
throw new TypeError('INVALID_TYPE', 'roles', 'Array or Collection of Roles or Snowflakes', true);
|
||||
}
|
||||
@@ -137,15 +137,15 @@ class GuildMemberRoleManager {
|
||||
const newRoles = this._roles.filter(role => !roleOrRoles.includes(role));
|
||||
return this.set(newRoles, reason);
|
||||
} else {
|
||||
roleOrRoles = this.guild.roles.resolve(roleOrRoles);
|
||||
if (roleOrRoles === null) {
|
||||
const roleID = this.guild.roles.resolveID(roleOrRoles);
|
||||
if (roleID === null) {
|
||||
throw new TypeError('INVALID_TYPE', 'roles', 'Array or Collection of Roles or Snowflakes', true);
|
||||
}
|
||||
|
||||
await this.client.api.guilds[this.guild.id].members[this.member.id].roles[roleOrRoles.id].delete({ reason });
|
||||
await this.client.api.guilds[this.guild.id].members[this.member.id].roles[roleID].delete({ reason });
|
||||
|
||||
const clone = this.member._clone();
|
||||
const newRoles = this._roles.filter(role => role.id !== roleOrRoles.id);
|
||||
const newRoles = this._roles.filter(role => role.id !== roleID);
|
||||
clone._roles = [...newRoles.keys()];
|
||||
return clone;
|
||||
}
|
||||
|
||||
@@ -911,11 +911,11 @@ class Guild extends Base {
|
||||
if (options.roles) {
|
||||
const roles = [];
|
||||
for (let role of options.roles instanceof Collection ? options.roles.values() : options.roles) {
|
||||
role = this.roles.resolve(role);
|
||||
if (!role) {
|
||||
let roleID = this.roles.resolveID(role);
|
||||
if (!roleID) {
|
||||
throw new TypeError('INVALID_TYPE', 'options.roles', 'Array or Collection of Roles or Snowflakes', true);
|
||||
}
|
||||
roles.push(role.id);
|
||||
roles.push(roleID);
|
||||
}
|
||||
options.roles = roles;
|
||||
}
|
||||
|
||||
@@ -285,11 +285,12 @@ class GuildMember extends Base {
|
||||
*/
|
||||
async edit(data, reason) {
|
||||
if (data.channel) {
|
||||
data.channel = this.guild.channels.resolve(data.channel);
|
||||
if (!data.channel || data.channel.type !== 'voice') {
|
||||
const voiceChannelID = this.guild.channels.resolveID(data.channel);
|
||||
const voiceChannel = this.guild.channels.cache.get(voiceChannelID);
|
||||
if (!voiceChannelID || (voiceChannel && voiceChannel?.type !== 'voice')) {
|
||||
throw new Error('GUILD_VOICE_CHANNEL_RESOLVE');
|
||||
}
|
||||
data.channel_id = data.channel.id;
|
||||
data.channel_id = voiceChannelID;
|
||||
data.channel = undefined;
|
||||
} else if (data.channel === null) {
|
||||
data.channel_id = null;
|
||||
|
||||
Reference in New Issue
Block a user