const { SlashCommandBuilder } = require('@discordjs/builders');
const { PermissionsBitField, EmbedBuilder } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('config')
.setDescription('Manage server configuration and settings')
.addSubcommand(subcommand =>
subcommand
.setName('plugin')
.setDescription('Enable or disable plugins')
.addStringOption(option =>
option
.setName('plugin_name')
.setDescription('The name of the plugin to manage')
.setRequired(true)
.addChoices(
{ name: 'Moderation', value: 'moderation' },
{ name: 'Logging', value: 'logging' },
{ name: 'Welcome', value: 'welcome' }
)
)
.addBooleanOption(option =>
option
.setName('enable')
.setDescription('Enable or disable the plugin')
.setRequired(true)
))
.addSubcommand(subcommand =>
subcommand
.setName('role')
.setDescription('Manage role permissions')
.addRoleOption(option =>
option
.setName('role')
.setDescription('Role to configure')
.setRequired(true)
)
.addStringOption(option =>
option
.setName('permission')
.setDescription('Permission to manage')
.setRequired(true)
.addChoices(
{ name: 'Administrator', value: 'ADMINISTRATOR' },
{ name: 'Manage Server', value: 'MANAGE_GUILD' },
{ name: 'Kick Members', value: 'KICK_MEMBERS' }
)
)
.addBooleanOption(option =>
option
.setName('enable')
.setDescription('Enable or disable the permission')
.setRequired(true)
)),
async execute(interaction) {
const { options, guild } = interaction;
const subcommand = options.getSubcommand();
if (!
interaction.member.permissions.has(PermissionsBitField.Flags.ManageGuild)) {
return interaction.reply({ content: 'You lack the required permissions
to use this command.', ephemeral: true });
}
if (subcommand === 'plugin') {
const pluginName = options.getString('plugin_name');
const enable = options.getBoolean('enable');
// Here, you'd update your config.json or database
// Example:
// config.plugins[pluginName] = enable;
const status = enable ? 'enabled' : 'disabled';
const embed = new EmbedBuilder()
.setColor(enable ? '#00FF00' : '#FF0000')
.setTitle('Plugin Management')
.setDescription(`The **${pluginName}** plugin has been ${status}.`)
.setFooter({ text: 'Use /config to manage more settings.' });
return interaction.reply({ embeds: [embed] });
} else if (subcommand === 'role') {
const role = options.getRole('role');
const permission = options.getString('permission');
const enable = options.getBoolean('enable');
if (enable) {
await
role.setPermissions(role.permissions.add(PermissionsBitField.Flags[permission]));
} else {
await
role.setPermissions(role.permissions.remove(PermissionsBitField.Flags[permission]))
;
}
const status = enable ? 'granted' : 'revoked';
const embed = new EmbedBuilder()
.setColor(enable ? '#00FF00' : '#FF0000')
.setTitle('Role Management')
.setDescription(`The **${permission}** permission has been $
{status} for the **${role.name}** role.`)
.setFooter({ text: 'Use /config to manage more settings.' });
return interaction.reply({ embeds: [embed] });
}
}
};