Fix nickname checks and add changing nicknames programmatically
This commit is contained in:
parent
c3e4563aeb
commit
c294df6b26
|
@ -53,6 +53,7 @@ export const Modules = {
|
|||
get NotificationSettingsModal() { return this._getModule('NotificationSettingsModal'); },
|
||||
get PrivacySettingsModal() { return this._getModule('PrivacySettingsModal'); },
|
||||
get UserProfileModal() { return this._getModule('UserProfileModal'); },
|
||||
get APIModule() { return this._getModule('APIModule'); },
|
||||
|
||||
get DiscordPermissions() { return this.DiscordConstants.Permissions; }
|
||||
};
|
||||
|
|
|
@ -170,10 +170,29 @@ export class GuildMember {
|
|||
* Opens the modal to change this user's nickname.
|
||||
*/
|
||||
openChangeNicknameModal() {
|
||||
if (DiscordApi.currentUser !== this) this.assertPermissions('MANAGE_NICKNAMES', Modules.DiscordPermissions.MANAGE_NICKNAMES);
|
||||
if (DiscordApi.currentUser === this.user)
|
||||
this.assertPermissions('CHANGE_NICKNAME', Modules.DiscordPermissions.CHANGE_NICKNAME);
|
||||
else this.assertPermissions('MANAGE_NICKNAMES', Modules.DiscordPermissions.MANAGE_NICKNAMES);
|
||||
|
||||
Modules.ChangeNicknameModal.open(this.guild_id, this.user_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the user's nickname on this guild.
|
||||
* @param {String} nickname The user's new nickname
|
||||
* @return {Promise}
|
||||
*/
|
||||
changeNickname(nick) {
|
||||
if (DiscordApi.currentUser === this.user)
|
||||
this.assertPermissions('CHANGE_NICKNAME', Modules.DiscordPermissions.CHANGE_NICKNAME);
|
||||
else this.assertPermissions('MANAGE_NICKNAMES', Modules.DiscordPermissions.MANAGE_NICKNAMES);
|
||||
|
||||
return Modules.APIModule.patch({
|
||||
url: `${Modules.DiscordConstants.Endpoints.GUILD_MEMBERS(this.guild_id)}/${DiscordApi.currentUser === this.user ? '@me/nick' : this.user_id}`,
|
||||
body: { nick }
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Kicks this user from the guild.
|
||||
* @param {String} reason A reason to attach to the audit log entry
|
||||
|
|
Loading…
Reference in New Issue