Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

djs-modules.js

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

djs-modules.js

The powerful and simplified commands Handler for Discord Bots.

  • 2.7.3
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

𝓶𝓸𝓭𝓾𝓵𝓮𝓼.𝓳𝓼

Yet another simplified commands handler for Discord bots.



Introduction

djs-modules.js is a package that creates and load all commands from a folder. It supports Slash commands and Context menu commands, and it's very simple and easy to use.

Table of Contents

  • modules.js
  • Introduction
  • Requirements
  • Installation
  • Example
  • Options
  • License (©)

Requirements

  • discord.js v14.9.0 or above.
  • Node.js v16.9.0 or above.

It's recommended to use TypeScript instead of JavaScript for the typings. If you're new on TypeScript, click here.

Installation

npm install djs-modules.js
yarn add djs-modules.js

Example

Example bot
├─── commands
│       └─── Utility
│               └─── ping.ts
└─── index.ts

index.ts:

import { Client } from 'discord.js';
import { Handler } from 'djs-modules.js';

const client = new Client({
    intents: ['Guilds']
});

const config = {
    token: 'Your bot token',
    id: 'Your bot ID',
    owner_id: 'Your account ID'
};

interface options {
    owner_only?: boolean
};

export const handler = new Handler<client, options>(client, './commands/', {
    includesDir: true
});

handler.on('commandLoad', (data) => console.log('Successfully loaded new command: ' + data.name));

handler.load();

handler.on('chatInputCreate', async (interaction, collection) => {
    const command = collection.get(interaction.commandName);

    if (!command) return;

    if (command.options) {
        if (command.options?.owner_only && interaction.user.id !== config.owner_id) {
            await interaction.reply({
                content: 'You are not the developer of the bot!',
                ephemeral: true
            });

            return;
        };
    };

    try {
        command.run(client, interaction, interaction.options);
    } catch { };
});

(async () => {
    await handler.deploy({
        token: config.token,
        applicationId: config.id
    });
})();

client.login(config.token);

ping.ts:

import { SlashCommandBuilder } from 'discord.js';
import { handler } from '../../index';

export default new handler.command({
    structure: new SlashCommandBuilder()
        .setName('ping')
        .setDescription('Replies with pong!'),
    options: {
        owner_only: true
    },
    run: async (client, interaction) => {
        await interaction.reply({
            content: `Pong! ${client.ws.ping}`
        });
    }
});

Options

Type parameters:

ParameterTypeOptional?DefaultDescription
ExtendedClientextends Client--The Discord bot client.
ExtendedCustomOptionsobjectYes{ }The custom options for each command builder.

The constructor:

OptionTypeOptional?DefaultDescription
includesDirbooleanYesfalseReads and loads other directories that exists in the provided folder path, including files.
defaultListenerbooleanYesfalseTrigger the property run from command builder whenever someone used it's application command name. If you have required custom options, you must set this property to false.
skipFileIfAlreadyExistbooleanYesfalseSkips a file if it's application command structure name already exists in the Collection. If the property's value is false, the original key's value (in collection) will be overwrited with another new module data.

deploy() method:

OptionTypeOptional?DefaultDescription
tokenstring--The Discord bot token.
applicationIdstring--The Discord bot application ID.
RESTRESTOptionsYesundefinedThe REST options.
guildIdstringYesundefinedThe guild ID to load the application commands on it.

Events

EventDescription
commandSkipWhenever a command has been skipped by the loader.
commandLoadWhenever a command has been successfully loaded.
chatInputCreateWhenever a Discord user has used a slash command.
contextMenuCreateWhenever a Discord user has used a context menu command (user or message).
userContextMenuCreateWhenever a Discord user has used a user context menu command.
messageContextMenuCreateWhenever a Discord user has used a message context menu command.
deployStartWhenever REST for application commands has started loading.
deployFinishWhenever REST has successfully finished loading app. commands.
deployErrorWhenever REST has caught an error.

License (©)

The MIT License

Copyright (c) 2023 T.F.A

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Keywords

FAQs

Package last updated on 29 May 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc