slacmdregistry
v4.3.6
Published
A modular slash command registry for Discord bots using Discord.js v14+. Handles dynamic loading and registration of commands with minimal setup.
Readme
slacmdregistry
A modular slash command registry for Discord bots using Discord.js v14+.
Handles dynamic loading and registration of commands with minimal setup.
Install
npm install slacmdregistry
Usage
const { deploy } = require('slacmdregistry');
deploy({
scope: 'global', // or 'guild'
guildId: 'YOUR_GUILD_ID', // required if scope is 'guild'
path: './commands',
log: true
});
Command Format
Each command lives in its own file inside /commands. Example:
// commands/ping.js
module.exports = {
name: 'ping',
description: 'Replies with Pong!',
options: [],
async execute(interaction) {
await interaction.reply('Pong!');
}
};
Examples
Kick Command
// commands/kick.js
const { EmbedBuilder } = require('discord.js');
module.exports = {
name: 'kick',
description: 'Kick a user from the server',
options: [
{
name: 'user',
description: 'The user to kick',
type: 6,
required: true
},
{
name: 'reason',
description: 'Reason for kick',
type: 3
}
],
async execute(interaction) {
const user = interaction.options.getUser('user');
const reason = interaction.options.getString('reason') || 'No reason provided';
const member = interaction.guild.members.cache.get(user.id);
if (!member) {
return interaction.reply({ content: 'User not found.', ephemeral: true });
}
try {
await member.kick(reason);
const embed = new EmbedBuilder()
.setTitle('User Kicked')
.setColor(0xff0000)
.addFields(
{ name: 'User', value: user.tag, inline: true },
{ name: 'Moderator', value: interaction.user.tag, inline: true },
{ name: 'Reason', value: reason }
)
.setThumbnail(user.displayAvatarURL({ dynamic: true }))
.setTimestamp();
await interaction.reply({ embeds: [embed] });
} catch (err) {
await interaction.reply({ content: `Failed to kick: ${err.message}`, ephemeral: true });
}
}
};
Ban Command
// commands/ban.js
module.exports = {
name: 'ban',
description: 'Ban a user from the server',
options: [
{
name: 'user',
description: 'The user to ban',
type: 6,
required: true
},
{
name: 'reason',
description: 'Reason for ban',
type: 3
}
],
async execute(interaction) {
const user = interaction.options.getUser('user');
const reason = interaction.options.getString('reason') || 'No reason provided';
const member = interaction.guild.members.cache.get(user.id);
if (!member) {
return interaction.reply({ content: 'User not found.', ephemeral: true });
}
try {
await member.ban({ reason });
await interaction.reply(`Banned ${user.tag} for: ${reason}`);
} catch (err) {
await interaction.reply({ content: `Failed to ban: ${err.message}`, ephemeral: true });
}
}
};
Embed-Only Command
// commands/serverinfo.js
const { EmbedBuilder } = require('discord.js');
module.exports = {
name: 'serverinfo',
description: 'Shows server information',
options: [],
async execute(interaction) {
const { guild } = interaction;
const embed = new EmbedBuilder()
.setTitle('Server Info')
.setColor(0x00bfff)
.addFields(
{ name: 'Name', value: guild.name, inline: true },
{ name: 'Members', value: `${guild.memberCount}`, inline: true }
)
.setThumbnail(guild.iconURL({ dynamic: true }))
.setTimestamp();
await interaction.reply({ embeds: [embed] });
}
};
Features
- Supports both global and guild slash commands
- Loads commands dynamically from a folder
- Embed-friendly and option-rich
- Minimal setup, maximum control
License
MIT