3.0.0-beta22feb09b • Published 1 year ago
@wilcosp/rex v3.0.0-beta22feb09b
Rex
An automated and easy to use command manager for discord.js
Description
Rex is a command manager for discord.js that automaticly handles importing the commands, (de)registering them to discord and routing interactions to the right command
Installation
Node.js 16.6.0 or newer is required.
npm install @wilcosp/rex
pnpm add @wilcosp/rex
yarn add @wilcosp/rex
Usage
initializing command manager
import { Client } from "discord.js";
import Rex from "@wilcosp/rex";
const client = new Client({
intents: ["GUILD_MESSAGES", "GUILDS"], //setting guild messages & messages will be needed to get guild message & message data when receiving interactions
});
bot.login(DISCORD_BOT_TOKEN);
const rex = new Rex(
client, //Rex will wait till discord.js client is ready
{
slashCommandsDir: SLASHCOMMAND_DIR, // location of slash commands from entry file
contextMenuDir: CONTEXT_DIR, // location of contextmenu command from entry file
modalDir: MODALS_DIR, // location of pre defined modals from entry file
componentsDir: COMPONENTS_DIR, // location of pre defined components from entry file
log: LOGGIN, //whether to have logging enabled (default false)
checkPermissions: CHECK_PERMS, // whether to check permissions when receiving the interaction (default true)
}
);
Creating a slash command
import { RexSlashCommand, RexSlashCommandBooleanOption, RexSlashCommandStringOption, RexSlashCommandUserOption, RexCommandReplyBuilder, RexEmbed } from "@wilcosp/rex";
// always export slash command, context menu commands, modals or components as the default, (commonjs can be with module.exports or exports.default)
export default new RexSlashCommand("avatar", "Get an avatar from yourself or another member") //
.addOptions(new RexSlashCommandUserOption("user", "The user you want to see the avatar from").setRequired(true)) //add the options you want to be available for slash commands
.setAutoDefer(true, true) // if you want Rex to auto defer when it takes long to reply
.setExecute(async interaction => {
const user = interaction.options.getUser("user");
const reply = new RexCommandReplyBuilder().setEphemeral(EPHEMERAL);
// You can use RexCommandReplyBuilder to make replying to an interaction easier, especially when it becomes complex with files and/or embeds
if (user) {
return interaction.reply(
reply.setEmbeds(
//Set Embeds does also allow Discord.js embeds or raw embed objects
new RexEmbed()
.setImage(
user.avatarURL({
dynamic: true,
})
)
.setColor(EMBED_COLOR)
)
);
}
return interaction.reply(reply.setContent("User/member couldn't be found"));
}); //add a callback that will handle the interaction
Support
If you're expiericing issues you can create an issue here
Roadmap
- When discord.js v14 releases to update Rex to support 14
- Real multi shard support
- check default member permissions during syncing commands
Contributing
You can contribute to Rex in some ways
- proposing features with an issue ticket
- updating documentation by making a merge request with your fork
- bug fixing or implementing features by making a merge request with your fork
Authors and acknowledgment
License
Rex is licensed under the Mozilla public 2.0 license (MPL-2.0)
check the license file for full license
3.0.0-beta23march29A
1 year ago
3.0.0-beta22feb09b
1 year ago