npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

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.