[go: up one dir, main page]

0% found this document useful (0 votes)
17 views2 pages

Message

This document defines a Discord bot command for managing server configuration and settings, including enabling/disabling plugins and managing role permissions. It utilizes the Discord.js library to create a slash command with subcommands for plugins and roles, requiring appropriate permissions to execute. The command provides feedback through embedded messages upon successful execution of the configuration changes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views2 pages

Message

This document defines a Discord bot command for managing server configuration and settings, including enabling/disabling plugins and managing role permissions. It utilizes the Discord.js library to create a slash command with subcommands for plugins and roles, requiring appropriate permissions to execute. The command provides feedback through embedded messages upon successful execution of the configuration changes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

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] });


}
}
};

You might also like