discordsmash
v1.2.0
Published
Wrapper of discord.js written in typescript to allow easier creation and management of discord commands. Also allows to use the latest version of discord.js without having to worry about changes in the interfaces
Downloads
4
Readme
DiscordSmash
DiscordSmash is a library build on top of discord.js to provide easier control over commands, components, and more. With the command system using a decorator design pattern, creating commands has never been easier.
Command management
DiscordSmash will create slash commands and manage them for you. All you need to do is register the file where your slash command is defined, and DiscordSmash will do the rest.
index.ts
// Create an instance of Bot
let bot = new Bot(botToken);
// Login to the bot
bot.login().then(async () => {
// Load all commands located in the commands folder
bot.defineFromFolder("./commands/");
// Load the command described in ./command.ts
bot.defineCommand("./command");
// Register all the command in the folder with discord
await bot.registerAllCommands(guildId);
// Make sure all permissions for the commands are set
await bot.updatePermissions(guildId);
// We are done!
console.log("Bot has completed loading!");
})
Creating commands
New commands are defined by creating a class that extends the CommandDef class. This is the base of your command, as it will prepare all defined commands and subcommands in your class for DiscordSmash to understand.
Each command is annotated with the @Base
decorator to indicate that the CommandDef describes a base command with a given name and description. After this, the user can simply add methods and annotate them with for example @BaseCommand
or @SubCommand
decorators to tell DiscordSmash that the current method listens for certain (sub-)commands.
Example
command.ts
@Base("testcommand", "This is a test command")
@AllowRolesByName("manager", "funny")
export default TestCommand extends CommandDef {
@SubCommand("first", "The first subcommand", false,
{name: "name", description: "a name", type: ArgumentType.String, required: true}
)
first(@Author author: GuildMember, @Param("name") name: string): InteractionReplyOptions {
// Do stuff
return {
content: `Hello ${name}!`,
ephemeral: true
}
}
}
Installing and usage
Using this library is only possible in TypeScript, due to the support of decorators. Next to this, the user should also make sure it is using the latest version of TypeScript, and that they enable the experimentalDecorators
flag.
Next to this, the DiscordSmash library is using the discord.js dev version (which can be installed using npm install discord.js@dev
) due to some features that have not been introduced in the stable version. Make sure that you are developing for this version.
This library can be used in two ways.
Cloning the repo
After cloning the repo, the user has to call the following in the repo folder:
npm run build
npm link
And run the following in their npm project folder:
npm link discordsmash
Installing from npm
The library can also be installed using:
npm install discordsmash
Documentation
For more information, the documentation can be found here.