load/unload commands

pull/1/head
Supositware 1 year ago
parent 2f0d6d6a42
commit 0b01712712

@ -0,0 +1,22 @@
import { SlashCommandBuilder } from 'discord.js';
export default {
data: new SlashCommandBuilder()
.setName('load')
.setDescription('load a command.')
.addStringOption(option =>
option.setName('file')
.setDescription('File location of the command.')
.setRequired(true)),
category: 'owner',
ownerOnly: true,
async execute(interaction, args, client) {
await interaction.deferReply();
let command = await import(`../../${args.file}`);
command = command.default;
client.commands.set(command.data.name, command);
return await interaction.editReply(`${command.data.name} has been loaded.`);
},
};

@ -0,0 +1,50 @@
import { SlashCommandBuilder } from 'discord.js';
import fs from 'node:fs';
export default {
data: new SlashCommandBuilder()
.setName('unload')
.setDescription('Unload a command and replace it with a placeholder')
.addStringOption(option =>
option.setName('commandname')
.setDescription('The command to unload.')
.setRequired(true))
.addStringOption(option =>
option.setName('placeholder')
.setDescription('The placeholder message you want for the command.'))
.addBooleanOption(option =>
option.setName('nofile')
.setDescription('Don\'t create the placeholder file')),
category: 'owner',
ownerOnly: true,
async execute(interaction, args, client) {
await interaction.deferReply();
if (!client.commands.has(args.commandname)) return await interaction.editReply('Command not found.');
if (!args.placeholder) args.placeholder = 'This command is unloaded, please check back later.';
if (!args.nofile) {
fs.writeFileSync(`./unloaded/${args.commandname}.js`, `
import { SlashCommandBuilder } from 'discord.js';
export default {
data: ${JSON.stringify(client.commands.get(args.commandname).data)},
category: '${client.commands.get(args.commandname).category}',
async execute(interaction) {
return interaction.reply('${args.placeholder}');
},
};
`);
}
client.commands.delete(args.commandname);
if (!args.nofile) {
let command = await import(`../../unloaded/${args.commandname}.js`);
command = command.default;
client.commands.set(args.commandname, command);
}
return await interaction.editReply(`${args.commandname} has been unloaded.`);
},
};
Loading…
Cancel
Save