Shasha/cmds/owner/unload.js
2021-06-28 18:12:39 +09:00

52 lines
1.4 KiB
JavaScript

const { oneLine } = require('common-tags');
const Command = require('../../node_modules/@iceprod/discord.js-commando/src/commands/base');
module.exports = class UnloadCommandCommand extends Command {
constructor(client) {
super(client, {
name: 'unload',
aliases: ['unload-command'],
group: 'owner',
memberName: 'unload',
description: 'Unloads a command.',
details: oneLine`
The argument must be the name/ID (partial or whole) of a command.
Only the bot owner(s) may use this command.
`,
examples: ['unload some-command'],
ownerOnly: true,
guarded: true,
args: [
{
key: 'command',
prompt: 'Which command would you like to unload?',
type: 'command'
}
]
});
}
async run(msg, args) {
args.command.unload();
if(this.client.shard) {
try {
await this.client.shard.broadcastEval(`
const ids = [${this.client.shard.ids.join(',')}];
if(!this.shard.ids.some(id => ids.includes(id))) {
this.registry.commands.get('${args.command.name}').unload();
}
`);
} catch(err) {
this.client.emit('warn', `Error when broadcasting command unload to other shards`);
this.client.emit('error', err);
await msg.reply(`Unloaded \`${args.command.name}\` command, but failed to unload on other shards.`);
return null;
}
}
await msg.reply(`Unloaded \`${args.command.name}\` command${this.client.shard ? ' on all shards' : ''}.`);
return null;
}
};