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

1.4.6 • Public • Published

discordutil

Discord NPM Version NPM Dependencies NPM Downloads GitHub Stars License

Powerful set of utilities for Discord.js. New to discordutil? Check out the API Reference.

  • An easy-to-use Command & Event Handler.
  • Anti-spam module to prevent raids. [Work-in-Progress]
  • A Swear Detector to detect swear words in a message.
  • Additional Utilities: formatDate(), msToReadable(), parseMs(), randomColor(), and randomNumber().

Installation

npm install discordutil

Usage

Importing the package

const DiscordUtil = require('discordutil');
const Discord = require('discord.js'); // optional

CommandHandler

const bot = new Discord.Client();
const handler = new DiscordUtil.CommandHandler({
  client: bot,
  commandDir: __dirname + '/commands',
  prefix: '!'
}).load();
 
// commands/ping.js
module.exports = {
  name: 'ping',
  aliases: ['pong'],
  run(client, message, args) {
    return message.reply('Pong!');
  }
}

EventHandler

const bot = new Discord.Client();
const handler = new DiscordUtil.EventHandler({
  client: bot,
  eventDir: __dirname + '/events'
}).load();
 
// events/ready.js
module.exports = client => {
  console.log(`Logged in as ${client.user.tag}!`);
}

Swear Detector

// Message event
const words = ['swear', 'words', 'here'];
if (DiscordUtil.isSwear(message.content, words)) {
  return message.reply('No swearing!');
}

Extra Utilities

DiscordUtil
  .formatDate(new Date()); // 10/8/2019
  .msToReadable(8.64e+7); // 24:00:00
  .parseMs(8.64e+7); // { days: 1, hours: 0, minutes: 0, seconds: 0, ... }
  .randomColor(); // #b35c44
  .randomNumber(10, 100); // 67
  .deconstructSnowflake(220954374770262017); // { timestamp: 1472750028079, ... }

Package Sidebar

Install

npm i discordutil

Weekly Downloads

1

Version

1.4.6

License

MIT

Unpacked Size

46.8 kB

Total Files

84

Last publish

Collaborators

  • chroventer