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

discordjs-modules

v0.3.1

Published

Discord.js modules handler that allows you handle all discord components and interactions like menus, modals, button, events and commands in one module directory.

Downloads

3

Readme

discordjs-modules

Discord.js modules handler that allows you handle all discord components (like menus, modals and buttons), events and commands in one module directory. You can easily add new features or remove old ones, just add or remove a module (folder) from the modules directory.

Installation

via npm

npm i discordjs-modules

via yarn

yarn add discordjs-modules

Getting Started

Import the handler initialization function into the main index.ts file

// index.ts

import { DiscordJSModules } from "discordjs-modules";
import { Client, GatewayIntentBits, Partials, Collection } from "discord.js";
import config from "./config.json";

const client = new Client({
  intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildMessages],
});

DiscordJSModules.init(client, config.token, { srcDir: __dirname });

client.login(config.token);

After starting the bot, the handler will create a new modules directory in the root folder. There you can create your own module as shown below:

├───node_modules
├───src
│    ├───index.ts
│    ├───modules <-- this folder will be created automatically
│    │   └───myFirstModule <-- this is a module created by you, name it whatever you want
│    │       ├───commands <-- this is commands directory, must always be named 'commands'
│    │       │   └───ban.ts (command file)
│    │       ├───buttons <-- this is buttons directory, must always be named 'buttons'
│    │       │   └───submit.ts (button file)
│    │       ├───modals <-- this is modals directory, must always be named 'modals'
│    │       │   └───form.ts (modal file)
│    │       ├───events <-- this is events directory, must always be named 'events'
│    │       │   └───messageCreate.ts (event file)
│    │       └───menus <-- this is menus directory, must always be named 'menus'
│    │           └───select-user.ts (menu file)
│    └───utils
│        └───discord
├───package.json
├───package-lock.json
├───config.json

[!IMPORTANT]
Remember! You must always use the correct directory names:
/commands for commands files
/events for events files
/buttons for buttons files
/menus for menus files
/modals for modal files

Structure of handler components files

Each component requires an appropriate structure of the exported object to work:

/commands/ban.ts

import { SlashCommandBuilder } from "discord.js";
import { CommandModule } from "discordjs-modules";

module.exports = <CommandModule<SlashCommandBuilder>>{
  data: new SlashCommandBuilder().setName("ban").setDescription("Ban user"),
  cooldown: 5, // (optional cooldown in seconds)
  async autocomplete(interaction) { // (optional)
    // your code to execute when autocomplete option is set to true
  },
  execute(interaction) {
    // your code to execute
  },
};

/events/messageCreate.ts

import { Events } from "discord.js";
import { EventModule } from "discordjs-modules";

module.exports = <EventModule<Events.MessageCreate>>{
  name: Events.MessageCreate,
  async execute(message) {
    // your code to execute
  },
};

/buttons/submit.ts

[!NOTE]
Buttons, menus and modals have the same file structure.

import { ButtonModule } from "discordjs-modules";
// or import { MenuModule } from "discordjs-modules"; if its menu file
// or import { ModalModule } from "discordjs-modules"; if its modal file

module.exports = <ButtonModule>{
  customId: "submit",
  async execute(interaction) {
    // your code to execute
  },
};

Global events and commands

The handler allows you to create global events and commands that do not need to be assigned to any module. All you need to do is create a commands or events folder in the project's root directory. The files structure is the same as in the modules.

├───node_modules
├───src
│    ├───index.ts
│    ├───commands <-- global commands here
│    │   └───globalCommand.ts
│    ├───events <-- global events here
│    │   └───guildMemberAdd.ts
│    ├───modules <-- this folder will be created automatically
│    │   └───myFirstModule <-- this is a module created by you, name it whatever you want
│    │       ├───commands <-- this is commands directory, must always be named 'commands'
│    │       │   └───ban.ts (command file)
│    │       ├───buttons <-- this is buttons directory, must always be named 'buttons'
│    │       │   └───submit.ts (button file)
│    │       ├───modals <-- this is modals directory, must always be named 'modals'
│    │       │   └───form.ts (modal file)
│    │       ├───events <-- this is events directory, must always be named 'events'
│    │       │   └───messageCreate.ts (event file)
│    │       └───menus <-- this is menus directory, must always be named 'menus'
│    │           └───select-user.ts (menu file)
│    └───utils
│        └───discord
├───package.json
├───package-lock.json
├───config.json