mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 00:53:31 +01:00
refactor(*): return the invalid element when erroring from Array (#5314)
This commit is contained in:
@@ -929,15 +929,16 @@ class Guild extends Base {
|
||||
if (this.members.cache.has(user)) return this.members.cache.get(user);
|
||||
options.access_token = options.accessToken;
|
||||
if (options.roles) {
|
||||
const roles = [];
|
||||
for (let role of options.roles instanceof Collection ? options.roles.values() : options.roles) {
|
||||
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(roleID);
|
||||
if (!Array.isArray(options.roles) && !(options.roles instanceof Collection)) {
|
||||
throw new TypeError('INVALID_TYPE', 'options.roles', 'Array or Collection of Roles or Snowflakes', true);
|
||||
}
|
||||
options.roles = roles;
|
||||
const resolvedRoles = [];
|
||||
for (const role of options.roles.values()) {
|
||||
const resolvedRole = this.roles.resolveID(role);
|
||||
if (!role) throw new TypeError('INVALID_ELEMENT', 'Array or Collection', 'options.roles', role);
|
||||
resolvedRoles.push(resolvedRole);
|
||||
}
|
||||
options.roles = resolvedRoles;
|
||||
}
|
||||
const data = await this.client.api.guilds(this.id).members(user).put({ data: options });
|
||||
// Data is an empty buffer if the member is already part of the guild.
|
||||
|
||||
Reference in New Issue
Block a user