mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 17:13:31 +01:00
Fix setting guild role positions (#751)
This commit is contained in:
@@ -23,6 +23,7 @@ class ActionsManager {
|
||||
this.register('GuildEmojiCreate');
|
||||
this.register('GuildEmojiDelete');
|
||||
this.register('GuildEmojiUpdate');
|
||||
this.register('GuildRolesPositionUpdate');
|
||||
}
|
||||
|
||||
register(name) {
|
||||
|
||||
30
src/client/actions/GuildRolesPositionUpdate.js
Normal file
30
src/client/actions/GuildRolesPositionUpdate.js
Normal file
@@ -0,0 +1,30 @@
|
||||
const Action = require('./Action');
|
||||
|
||||
class GuildRolesPositionUpdate extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
|
||||
const guild = client.guilds.get(data.guild_id);
|
||||
if (guild) {
|
||||
for (const partialRole of data.roles) {
|
||||
const role = guild.roles.get(partialRole.id);
|
||||
if (role) {
|
||||
role.position = partialRole.position;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
guild,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Emitted whenever a guild role is created.
|
||||
* @event Client#guildRoleCreate
|
||||
* @param {Guild} guild The guild that the role was created in.
|
||||
* @param {Role} role The role that was created.
|
||||
*/
|
||||
|
||||
module.exports = GuildRolesPositionUpdate;
|
||||
@@ -677,6 +677,19 @@ class RESTMethods {
|
||||
}).catch(reject);
|
||||
});
|
||||
}
|
||||
|
||||
setRolePositions(guildID, roles) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.rest.makeRequest('patch', Constants.Endpoints.guildRoles(guildID), true, roles)
|
||||
.then(() => {
|
||||
resolve(this.rest.client.actions.GuildRolesPositionUpdate.handle({
|
||||
guild_id: guildID,
|
||||
roles,
|
||||
}).guild);
|
||||
})
|
||||
.catch(reject);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = RESTMethods;
|
||||
|
||||
Reference in New Issue
Block a user