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

@fansems1/discordcommandbo

v1.0.5

Published

A simple command manager for discord-simple-api

Downloads

72

Readme

Discord Command Manager

A lightweight and flexible command manager for Discord bots, designed to work seamlessly with the discord-simple-api package. This command manager simplifies the process of handling commands and provides a structured way to organize your bot's functionalities.

Features

  • Easy Command Registration: Register commands with their callbacks for efficient command handling.
  • Help Command Generation: Automatically generates a help command that lists all available commands and their descriptions.
  • Error Handling: Built-in error handling to ensure smooth command execution and feedback on execution errors.
  • Bot Message Ignoring: Automatically ignores messages from bots to prevent command loops.

Installation

Ensure you have discord-simple-api installed in your project. If not, you can install it along with discord-command-manager using npm:

npm install discord-simple-api
npm install discord-command-manager

Usage

First, initialize your Discord instance from discord-simple-api and then create a CommandManager instance with it:

const { Discord } = require('discord-simple-api');
const CommandManager = require('discord-command-manager');

// Initialize the Discord instance with your bot token
const discordInstance = new Discord('YOUR_DISCORD_BOT_TOKEN');

// Create the CommandManager instance
const commandManager = new CommandManager(discordInstance);

// Register commands
commandManager.registerCommand('hello', async (args, message) => {
  // Logic for the command
  console.log(`Hello command triggered by ${message.author.username}`);
});

// Generate a help command
commandManager.generateHelpCommand();

// Example handleMessage usage within an onMessage listener
discordInstance.on('message', message => {
  commandManager.handleMessage(message);
});

Registering Commands

To register a command, use the registerCommand method. It takes a command name and a callback function as arguments. The callback function is called with args and message when the command is triggered:

commandManager.registerCommand('greet', async (args, message) => {
  const reply = `Hello, ${args[0]}!`;
  // Assuming sendMessageToChannel sends a message to the specified channel
  await discordInstance.sendMessageToChannel(message.channel.id, reply);
});

Contributing

Contributions are welcome! If you have suggestions for improvements or bug fixes, feel free to make a pull request or open an issue.