djs-handler
TypeScript icon, indicating that this package has built-in type declarations

1.3.3 • Public • Published

djs-handler

Discord.js command handler

npm bundle size npm GitHub issues GitHub pull requests NPM npm node-current

Example

for this file system:

commands directory
- command1.js
- command2.js
- command3.js
- command4.js
main file
shard file
package.json file
package-lock.json file
...

main file

const { Bot } = require('djs-handler'); // import module
const client = new Bot(/*your token here*/, { // constructor
    prefix: // your bot's prefix
    // you can add typing boolean to use typing for messages
    // you can add allowAllDM boolean to allow DM messages from everyone
    // you can ass DMWhitelist array with Discord user IDs to allow DM messages from specific users
    // you can add allowAllBot boolean to allow messages from all bot
    // you can ass BotWhitelist array with Discord user IDs to allow messages from specific bots
});
client.config(/*path of command files*/); // config all the files and login with the given token
// client.configDir is also available. See the references for more information.

command file

module.exports = {
    name: 'ping',
    aliases: ['latency'],
    run: async (client, message, args) => {
        message.channel.send(client.ws.ping);
    }
}

reload command file

module.exports = {
    name: 'reload',
    run: async (client, message, args) => {
        if (message.author.id != 'dev_id') return message.channel.send('You aren\'t a developer'); // replace 'dev_id' with your id.
        client.reload().then(x => message.channel.send(`reloaded ${x} commands`)).catch(() => message.channel.send('there was an error while reloading'));
    }
}

Tip: you can use Bot.configDir(dir) and Bot.reloadDir() for this file system:

commands directory
- category1
- - command1.js
- - command2.js
- category2
- - command3.js
- - command4.js
main file
shard file
package.json
package-lock.json
...

Bug report

Please use the issue tracker.

contributor

mswgen

Package Sidebar

Install

npm i djs-handler

Weekly Downloads

25

Version

1.3.3

License

MIT

Unpacked Size

14.2 kB

Total Files

5

Last publish

Collaborators

  • mswgen