thaldrin/DiscordModules/Settings/prefix.js

60 lines
1.8 KiB
JavaScript

const Command = require('../../src/structures/Command');
module.exports = class Prefix extends Command {
constructor() {
super({
name: 'prefix',
description: 'Add or Remove a prefix',
aliases: [],
module: 'Settings',
cooldown: 10,
guildOnly: true,
developerOnly: false
});
}
async command(ctx) {
const PrefixEmbed = new ctx.utils.discord.MessageEmbed();
PrefixEmbed.setColor(ctx.config.color);
let ARG = ctx.args[0];
ctx.args.shift();
let Prefix = ctx.args.join(' ');
let Server = await ctx.db.servers.get(ctx.guild.id);
Server.prefix.shift();
Server.prefix.shift();
Server.prefix.shift();
switch (ARG) {
case 'a':
case 'add':
if (ctx.args === [] || ctx.args.join(' ').trim() === '') return ctx.send('No Prefix was given');
ctx.utils.db.prefix
.add(ctx, Prefix)
.then(async () => {
let NServer = await ctx.db.servers.get(ctx.guild.id);
PrefixEmbed.setTitle(`Prefixes for ${ctx.guild.name}`);
PrefixEmbed.setDescription(`${NServer.prefix.join(', ') || ctx.db.defaults.server.prefix}`);
ctx.send(PrefixEmbed);
})
.catch((err) => ctx.send(err));
break;
case 'r':
case 'remove':
if (ctx.args === [] || ctx.args.join(' ').trim() === '') return ctx.send('No Prefix was given');
ctx.utils.db.prefix
.remove(ctx, Prefix)
.then(async (r) => {
let NServer = await ctx.db.servers.get(ctx.guild.id);
ctx.send('Current Prefixes are:\n' + NServer.prefix.join(', '));
})
.catch((err) => ctx.send(err));
break;
default:
PrefixEmbed.setTitle('Help');
PrefixEmbed.addField('a / add <prefix>', 'Add a Prefix', true);
PrefixEmbed.addField('r / remove <prefix>', 'Remove a Prefix', true);
ctx.send(PrefixEmbed);
break;
}
}
};