aboutsummaryrefslogtreecommitdiff
path: root/src/commands/moderation/KickCommand.ts
diff options
context:
space:
mode:
authorTymanWasTaken <32660892+tymanwastaken@users.noreply.github.com>2021-04-27 21:06:22 -0600
committerTymanWasTaken <32660892+tymanwastaken@users.noreply.github.com>2021-04-27 21:06:22 -0600
commit763fb7d98c3accbb21adf035a7cf0a83cb9533c9 (patch)
tree9d333fbca2a2a8e19d79904a4e29226174925cfc /src/commands/moderation/KickCommand.ts
downloadtanzanite-763fb7d98c3accbb21adf035a7cf0a83cb9533c9.tar.gz
tanzanite-763fb7d98c3accbb21adf035a7cf0a83cb9533c9.tar.bz2
tanzanite-763fb7d98c3accbb21adf035a7cf0a83cb9533c9.zip
legit just copy utilibot v2 code
Diffstat (limited to 'src/commands/moderation/KickCommand.ts')
-rw-r--r--src/commands/moderation/KickCommand.ts72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/commands/moderation/KickCommand.ts b/src/commands/moderation/KickCommand.ts
new file mode 100644
index 0000000..0dc4276
--- /dev/null
+++ b/src/commands/moderation/KickCommand.ts
@@ -0,0 +1,72 @@
+import { BotCommand } from '../../lib/extensions/BotCommand';
+import { BotMessage } from '../../lib/extensions/BotMessage';
+import { Modlog, ModlogType } from '../../lib/types/Models';
+import { GuildMember } from 'discord.js';
+
+export default class PrefixCommand extends BotCommand {
+ constructor() {
+ super('kick', {
+ aliases: ['kick'],
+ args: [
+ {
+ id: 'user',
+ type: 'member',
+ prompt: {
+ start: 'What user would you like to kick?',
+ retry: 'Invalid response. What user would you like to kick?'
+ }
+ },
+ {
+ id: 'reason'
+ }
+ ],
+ clientPermissions: ['KICK_MEMBERS'],
+ userPermissions: ['KICK_MEMBERS']
+ });
+ }
+ async exec(
+ message: BotMessage,
+ { user, reason }: { user: GuildMember; reason?: string }
+ ): Promise<void> {
+ let modlogEnry: Modlog;
+ try {
+ modlogEnry = Modlog.build({
+ user: user.id,
+ guild: message.guild.id,
+ moderator: message.author.id,
+ type: ModlogType.KICK,
+ reason
+ });
+ await modlogEnry.save();
+ } catch (e) {
+ console.error(e);
+ await message.util.send(
+ 'Error saving to database. Please report this to a developer.'
+ );
+ return;
+ }
+ try {
+ await user.send(
+ `You were kicked in ${message.guild.name} with reason \`${
+ reason || 'No reason given'
+ }\``
+ );
+ } catch (e) {
+ await message.channel.send('Error sending message to user');
+ }
+ try {
+ await user.kick(
+ `Kicked by ${message.author.tag} with ${
+ reason ? `reason ${reason}` : 'no reason'
+ }`
+ );
+ } catch {
+ await message.util.send('Error kicking :/');
+ await modlogEnry.destroy();
+ return;
+ }
+ await message.util.send(
+ `Kicked <@!${user.id}> with reason \`${reason || 'No reason given'}\``
+ );
+ }
+}