fix and add role cmd
parent
98f89b5bfd
commit
028094aa87
|
@ -1,12 +1,12 @@
|
|||
import { Message } from 'eris';
|
||||
import { Message, Role as DRole } from 'eris';
|
||||
import { Client, Command } from '../class';
|
||||
|
||||
export default class Role extends Command {
|
||||
constructor(client: Client) {
|
||||
super(client);
|
||||
this.name = 'role';
|
||||
this.description = 'Manage the roles of a member';
|
||||
this.usage = 'role <user> <roles>';
|
||||
this.description = 'Manage the roles of a member.';
|
||||
this.usage = `${this.client.config.prefix}role <user> <roles>`;
|
||||
this.permissions = 6;
|
||||
this.enabled = true;
|
||||
}
|
||||
|
@ -14,27 +14,28 @@ export default class Role extends Command {
|
|||
public async run(message: Message, args: string[]) {
|
||||
try {
|
||||
if (args.length < 2) return this.client.commands.get('help').run(message, [this.name]);
|
||||
const member = this.client.util.resolveMember(args[0], message.guild);
|
||||
const member = this.client.util.resolveMember(args[0], this.mainGuild);
|
||||
if (!member) return this.error(message.channel, 'Member not found');
|
||||
if (!this.client.util.moderation.checkPermissions(member, message.member)) return this.error(message.channel, 'Permission Denied.');
|
||||
// if (!this.client.util.moderation.checkPermissions(member, message.member)) return this.error(message.channel, 'Permission denied.');
|
||||
const rolesList = args.slice(1).join(' ').split(', ');
|
||||
const rolesToAdd = [];
|
||||
const rolesToRemove = [];
|
||||
let stop = false;
|
||||
for (const arg of rolesList) {
|
||||
const action = arg[0];
|
||||
let role;
|
||||
let role: DRole;
|
||||
if (action !== '+' && action !== '-') {
|
||||
role = this.client.util.resolveRole(arg, message.guild);
|
||||
role = this.client.util.resolveRole(arg, this.mainGuild);
|
||||
if (!role) {
|
||||
stop = true;
|
||||
return this.error(message.channel, `Role \`${arg}\` not found.`);
|
||||
}
|
||||
if (member.roles.includes(role.id)) return rolesToRemove.push(role);
|
||||
return rolesToAdd.push(role);
|
||||
rolesToAdd.push(role);
|
||||
continue;
|
||||
}
|
||||
if (action === '+') {
|
||||
role = this.client.util.resolveRole(arg.slice(1), message.guild);
|
||||
role = this.client.util.resolveRole(arg.slice(1), this.mainGuild);
|
||||
if (!role) {
|
||||
stop = true;
|
||||
return this.error(message.channel, `Role \`${arg.slice(1)}\` not found.`);
|
||||
|
@ -43,10 +44,11 @@ export default class Role extends Command {
|
|||
stop = true;
|
||||
return this.error(message.channel, `You already have the role \`${role.name}\`.`);
|
||||
}
|
||||
return rolesToAdd.push(role);
|
||||
rolesToAdd.push(role);
|
||||
continue;
|
||||
}
|
||||
if (action === '-') {
|
||||
role = this.client.util.resolveRole(arg.slice(1), message.guild);
|
||||
role = this.client.util.resolveRole(arg.slice(1), this.mainGuild);
|
||||
if (!role) {
|
||||
stop = true;
|
||||
return this.error(message.channel, `Role \`${arg.slice(1)}\` not found.`);
|
||||
|
@ -55,10 +57,12 @@ export default class Role extends Command {
|
|||
stop = true;
|
||||
return this.error(message.channel, `You don't have the role \`${role.name}\``);
|
||||
}
|
||||
return rolesToRemove.push(role);
|
||||
rolesToRemove.push(role);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (stop) return;
|
||||
// eslint-disable-next-line
|
||||
// if (stop) return;
|
||||
rolesToAdd.forEach((role) => member.addRole(role.id));
|
||||
rolesToRemove.forEach((role) => member.removeRole(role.id));
|
||||
return this.success(message.channel, `Changed the roles for ${member.username}#${member.discriminator}${rolesToAdd.length > 0 ? `, added \`${rolesToAdd.map((r) => r.name).join('`, `')}\`` : ''}${rolesToRemove.length > 0 ? `, removed \`${rolesToRemove.map((r) => r.name).join('`, `')}\`` : ''}`);
|
||||
|
|
Loading…
Reference in New Issue