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

djs-handlers

v1.0.6

Published

Extended client functionlity, command and event handler for discord.js v14.

Downloads

1

Readme

djs-handlers

Small package for discord.js written in Typescript that exports 3 classes and the corresponding types:

  • Command
  • Event
  • ExtendedClient

First, you need to install the package using your package manager.

npm install djs-handlers

ExtendedClient

The ExtendedClient holds a Collection() of commands and has 2 methods that are exposed to the user.

To use the client, you first need to import it and then instantiate the class.

import { ExtendedClient } from 'djs-handlers';
import { GatewayIntentBits, Partials } from 'discord.js';

const client = new ExtendedClient{
  intents: [
    GatewayIntentBits.Guilds,
  ],
  partials: [Partials.GuildMember],
}

client.start({
  botToken: 'your discord token',
  guildID: 'your guild id, if you want to register the commands to a guild',
  commandsPath: './path/to/commandfolder',
  eventsPath: './path/to/eventfolder',
  type: 'commonJS',
  globalCommands: false,
  registerCommands: true,
})

The global property accepts a boolean indicating wether you want to register the commands to your application rather than a guild.

The registerCommands property accepts a boolean indicating wether you want to register the commmands on startup. You can change this during development to prevent spamming the API.

You can also remove all commands from your guild or application by using the remove() method.

client.removeCommands();

Inside your sources folder, create 2 directories with the names commands and events. Those hold all your events and the corresponding code and all your commands.

To create a new command, create a new file in src/commands/ping.ts.

import { Command } from 'djs-handlers'

export default new Command({
  name: 'ping',
  description: 'Pings a user!',
  options: [
    {
      name: 'target',
      description: 'The user you want to ping.',
      type: ApplicationCommandOptionType.User,
      required: true,
    }
  ]
  execute: async ({ interaction, args }) => {
    const targetUser = args.getUser('target')

    await interaction.reply(`<@${targetUser.id}>`)
  }
});

To create a new event, create a new file in src/commands/ready.ts.

import { Event } from 'djs-handlers';

export default new Event('ready', (client) => {
  console.log(`Bot is ready! Logged in as ${client.user.tag}`);
});

If you want to jumpstart your development process, make sure to check out my djs-template repository which provides you with examples and a working layout. Make sure to checkout the branch you are interested in (Typescript, CommonJS, ESModules).

If you find any issues or have suggestions please make sure to report them on the issue tracker.

You can also write me an email and/or join my discord server.

Thank you for using my repository and good luck with your next Discord Bot!