38 lines
1.5 KiB
TypeScript
38 lines
1.5 KiB
TypeScript
import { Message, User, Member } from 'eris';
|
|
import { Client, Command } from '../class';
|
|
|
|
export default class Kick extends Command {
|
|
constructor(client: Client) {
|
|
super(client);
|
|
this.name = 'kick';
|
|
this.description = 'Kicks a member from the guild.';
|
|
this.usage = 'kick <member> [reason]';
|
|
this.permissions = 3;
|
|
this.guildOnly = true;
|
|
this.enabled = true;
|
|
}
|
|
|
|
public async run(message: Message, args: string[]) {
|
|
try {
|
|
if (!args[0]) return this.client.commands.get('help').run(message, [this.name]);
|
|
let user: Member = this.client.util.resolveMember(args[0], message.guild);
|
|
if (!user) {
|
|
try {
|
|
user = await this.client.getRESTGuildMember(this.client.config.guildID, args[0]);
|
|
} catch {
|
|
return this.error(message.channel, 'Cannot find user.');
|
|
}
|
|
}
|
|
if (user && !this.client.util.moderation.checkPermissions(user, message.member)) return this.error(message.channel, 'Permission Denied.');
|
|
message.delete();
|
|
|
|
const reason: string = args[1];
|
|
if (reason.length > 512) return this.error(message.channel, 'Kick reasons cannot be longer than 512 characters.');
|
|
await this.client.util.moderation.kick(user, message.member, reason);
|
|
return this.success(message.channel, `${user.username}#${user.id} has been kicked.`);
|
|
} catch (err) {
|
|
return this.client.util.handleError(err, message, this, false);
|
|
}
|
|
}
|
|
}
|