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 🙏

© 2026 – Pkg Stats / Ryan Hefner

discord-eventhandlers

v1.0.4

Published

Event handler for easy maintain your application discord.js

Readme

discord-eventHandlers Documentation

Installation

To install the package, use the following command:

npm install discord-eventhandlers

Setup guide

import { EventHandlers } from 'discord-eventmanager';
import { Client } from 'discord.js';

// Initialize your Discord client
const client = new Client({ intents: [] }); // Configure intents as needed

// Create a new instance of EventHandlers
new EventHandlers({
    client,
    commandsPath: "src/commands", // Path to your commands folder or file
    eventsPath: "src/events", // Path to your events folder or file
    db: {  
        dbPath: "src/db", // Path to the database folder
        database: [
            "mongoose" // Name of the database folder within the db folder
        ] 
    },
    devServer: "943929342490482" // Optional: Specify a development server for exclusive command updates
});

example structure folders / files

folder / file structure

├── src
│   ├── commands
│   │   ├── moderator
│   │   │   ├── ping.js // you can nested a much as u want  
│   │   ├── admin
│   │   ├── misc
│   │   ├── daily
│   ├── events
│   │   ├── messageCreate
│   │   │   ├── 01Index.js  // This file will execute before index.js
│   │   │   ├── index.js    // You can name this file as needed
│   │   ├── interactionCreate // Configure command prefixes before execution
│   │   ├── guildMemberAdd
│   ├── db
│   │   ├── mongoose        // Ensure the folder name matches the database property
├── .env                     // Environment variables
├── index.js                 // Root application file
└── package.json

example for the command


export default {
    command:{
        name: 'ping',
        description: 'Replies with the bot ping!'
    },
    callback: async ({client, eventArg}) => {

        await eventArg.deferReply();

        const reply = await eventArg.fetchReply();
        const ping = reply.createdTimestamp - eventArg.createdTimestamp;

        eventArg.editReply(
        `Pong! Client ${ping}ms | Websocket: ${client.ws.ping}ms`
        );

        return
    },
};

or


import { SlashCommandBuilder } from 'discord.js';

export default {
    command: new SlashCommandBuilder()
        .setName('ping')
        .setDescription('Replies with the bot ping!'),
    async execute({eventArg}) {
        await eventArg.deferReply();

        const reply = await eventArg.fetchReply();
        const ping = reply.createdTimestamp - eventArg.createdTimestamp;

        await eventArg.editReply(
            `Pong! Client ${ping}ms | Websocket: ${eventArg.client.ws.ping}ms`
        );
    },
};

note: you can use normal export {} or default. but for export u cannot import greater than one object or variable


import { SlashCommandBuilder } from 'discord.js';

const command = {
    command: new SlashCommandBuilder()
        .setName('ping')
        .setDescription('Replies with the bot ping!'),
    async execute({eventArg}) {
        await eventArg.deferReply();

        const reply = await eventArg.fetchReply();
        const ping = reply.createdTimestamp - eventArg.createdTimestamp;

        await eventArg.editReply(
            `Pong! Client ${ping}ms | Websocket: ${eventArg.client.ws.ping}ms`
        );
    },
};

export {
    command
}

params for the callback function


callback: ({ client, eventArg, command, db }) // this all u can get with singgle callback func  

client= client objek from Client() instance discord.js 
eventArg= eventArg for interactionCreate 
command= your object command from ur export except callback function 
db= your object db instance if u set db path from eventHandlers 

example command params


export default {
    command: new SlashCommandBuilder()
        .setName('ping')
        .setDescription('Replies with the bot ping!'),
    async callback({eventArg, db, command}) {
        await eventArg.deferReply();
         
        console.log(command.devOnly)
        console.log(command.someRandomVar) 

        db.mongoose.user // this is ur user schema/model, the mongoose name is the prefix name from the name folder db/mongoose

        const reply = await eventArg.fetchReply();
        const ping = reply.createdTimestamp - eventArg.createdTimestamp;

        await eventArg.editReply(
            `Pong! Client ${ping}ms | Websocket: ${eventArg.client.ws.ping}ms`
        );
    },
    devOnly: true, 
    someRandomVar: "bla bla bla",
    ring: false // or whatever you want to
};

note: params command object is gonna go trough the events interactionCreate folder first (if exist) before reaching the callback function so you can set prefix or middleware before the callback function is called

example event events/interactionCreate


const o = async ({client, eventArg, command, db}) => { 
    // Check if the user has the required permissions
  const requiredPermissions = command.permissionsRequired || [];
  const userPermissions = eventArg.member.permissions;

  // Check if the user has the required permissions
  for (const permission of requiredPermissions) {
    if (!userPermissions.has(permission)) {
      return `❌ You do not have the required permissions to run this command. Missing: ${permission}`;
    }
  }

  // Check if the bot has the required permissions
  const botPermissions = command.botPermissions || [];
  const botMember = await eventArg.guild.members.fetch(eventArg.client.user.id);
  const botPermissionsInChannel = botMember.permissionsIn(eventArg.channel);

  // Check if the bot has the required permissions
  for (const permission of botPermissions) {
    if (!botPermissionsInChannel.has(permission)) {
      return `❌ The bot does not have the required permissions in this channel. Missing: ${permission}`;
    }
  }

  // If both checks pass, return null (no error)
  return null;
}

export {
    o
}

note: the param command is only there for interactionCreate events so if ur folder named messageCreate it should be like this


function ({client, eventArg, db})