mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-19 13:03:31 +01:00
cleanup(GuildMember{RoleStore}): Rewrite to async/await (#3072)
- Fixed a bug where `GuildMemberRoleStore#{add,remove}` would create a rejected promise inside a promise, instead of rejecting the first one.
- Fixed a bug where `GuildMember#edit` with a specified unknown channel would throw synchronously, instead of rejecting asynchronously.
This commit is contained in:
@@ -67,8 +67,8 @@ class GuildMemberRoleStore extends Collection {
|
|||||||
if (roleOrRoles instanceof Collection || roleOrRoles instanceof Array) {
|
if (roleOrRoles instanceof Collection || roleOrRoles instanceof Array) {
|
||||||
roleOrRoles = roleOrRoles.map(r => this.guild.roles.resolve(r));
|
roleOrRoles = roleOrRoles.map(r => this.guild.roles.resolve(r));
|
||||||
if (roleOrRoles.includes(null)) {
|
if (roleOrRoles.includes(null)) {
|
||||||
return Promise.reject(new TypeError('INVALID_TYPE', 'roles',
|
throw new TypeError('INVALID_TYPE', 'roles',
|
||||||
'Array or Collection of Roles or Snowflakes', true));
|
'Array or Collection of Roles or Snowflakes', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
const newRoles = [...new Set(roleOrRoles.concat(...this.values()))];
|
const newRoles = [...new Set(roleOrRoles.concat(...this.values()))];
|
||||||
@@ -76,8 +76,8 @@ class GuildMemberRoleStore extends Collection {
|
|||||||
} else {
|
} else {
|
||||||
roleOrRoles = this.guild.roles.resolve(roleOrRoles);
|
roleOrRoles = this.guild.roles.resolve(roleOrRoles);
|
||||||
if (roleOrRoles === null) {
|
if (roleOrRoles === null) {
|
||||||
return Promise.reject(new TypeError('INVALID_TYPE', 'roles',
|
throw new TypeError('INVALID_TYPE', 'roles',
|
||||||
'Array or Collection of Roles or Snowflakes', true));
|
'Array or Collection of Roles or Snowflakes', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
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[roleOrRoles.id].put({ reason });
|
||||||
@@ -98,8 +98,8 @@ class GuildMemberRoleStore extends Collection {
|
|||||||
if (roleOrRoles instanceof Collection || roleOrRoles instanceof Array) {
|
if (roleOrRoles instanceof Collection || roleOrRoles instanceof Array) {
|
||||||
roleOrRoles = roleOrRoles.map(r => this.guild.roles.resolve(r));
|
roleOrRoles = roleOrRoles.map(r => this.guild.roles.resolve(r));
|
||||||
if (roleOrRoles.includes(null)) {
|
if (roleOrRoles.includes(null)) {
|
||||||
return Promise.reject(new TypeError('INVALID_TYPE', 'roles',
|
throw new TypeError('INVALID_TYPE', 'roles',
|
||||||
'Array or Collection of Roles or Snowflakes', true));
|
'Array or Collection of Roles or Snowflakes', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
const newRoles = this.filter(role => !roleOrRoles.includes(role));
|
const newRoles = this.filter(role => !roleOrRoles.includes(role));
|
||||||
@@ -107,8 +107,8 @@ class GuildMemberRoleStore extends Collection {
|
|||||||
} else {
|
} else {
|
||||||
roleOrRoles = this.guild.roles.resolve(roleOrRoles);
|
roleOrRoles = this.guild.roles.resolve(roleOrRoles);
|
||||||
if (roleOrRoles === null) {
|
if (roleOrRoles === null) {
|
||||||
return Promise.reject(new TypeError('INVALID_TYPE', 'roles',
|
throw new TypeError('INVALID_TYPE', 'roles',
|
||||||
'Array or Collection of Roles or Snowflakes', true));
|
'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[roleOrRoles.id].delete({ reason });
|
||||||
|
|||||||
@@ -248,7 +248,7 @@ class GuildMember extends Base {
|
|||||||
* @param {string} [reason] Reason for editing this user
|
* @param {string} [reason] Reason for editing this user
|
||||||
* @returns {Promise<GuildMember>}
|
* @returns {Promise<GuildMember>}
|
||||||
*/
|
*/
|
||||||
edit(data, reason) {
|
async edit(data, reason) {
|
||||||
if (data.channel) {
|
if (data.channel) {
|
||||||
data.channel = this.guild.channels.resolve(data.channel);
|
data.channel = this.guild.channels.resolve(data.channel);
|
||||||
if (!data.channel || data.channel.type !== 'voice') {
|
if (!data.channel || data.channel.type !== 'voice') {
|
||||||
@@ -266,12 +266,12 @@ class GuildMember extends Base {
|
|||||||
} else {
|
} else {
|
||||||
endpoint = endpoint.members(this.id);
|
endpoint = endpoint.members(this.id);
|
||||||
}
|
}
|
||||||
return endpoint.patch({ data, reason }).then(() => {
|
await endpoint.patch({ data, reason });
|
||||||
const clone = this._clone();
|
|
||||||
data.user = this.user;
|
const clone = this._clone();
|
||||||
clone._patch(data);
|
data.user = this.user;
|
||||||
return clone;
|
clone._patch(data);
|
||||||
});
|
return clone;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user