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.js-toolbox

v1.0.3

Published

A utility library for Discord.js v14 bots — embeds, moderation helpers, pagination, formatters, and more.

Downloads

362

Readme

npm version downloads discord.js license

Build production-ready Discord bots faster — safe moderation, clean embeds, pagination, validation, cooldowns, and more.


Why use this?

Most Discord bots break in the same places:

  • Moderation crashes due to role hierarchy or missing permissions.
  • Embed code copy-pasted everywhere with no consistency.
  • Pagination logic rewritten for every command.
  • No reusable cooldown or validation handling.

discord.js-toolbox solves all of that in one package, with safe defaults and zero unnecessary abstractions.


Installation

npm install discord.js discord.js-toolbox

Quick Example

const {
  successEmbed,
  errorEmbed,
  safeBan,
  CooldownManager,
} = require('discord.js-toolbox');

const cooldowns = new CooldownManager();

module.exports = {
  name: 'ban',
  async execute(interaction) {
    const { onCooldown, remaining } = cooldowns.check('ban', interaction.user.id, 5000);
    if (onCooldown) {
      return interaction.reply({
        embeds: [errorEmbed(`Wait ${Math.ceil(remaining / 1000)}s before reusing this command.`)],
        ephemeral: true,
      });
    }

    try {
      await safeBan(interaction.member, 'Rule violation.');
      interaction.reply({ embeds: [successEmbed('User banned successfully.')] });
    } catch (err) {
      interaction.reply({ embeds: [errorEmbed(err.message)] });
    }
  },
};

Modules

Moderation

Prevents crashes from permission errors and hierarchy issues before they happen.

canModerate(target, executor)              // → { ok, reason }
safeBan(member, reason, deleteMessageDays)
safeKick(member, reason)
safeTimeout(member, durationMs, reason)
dmUser(member, embed)                      // → true/false

Duration parsing:

parseDuration('10m')      // → 600000 (ms)
parseDuration('2h')       // → 7200000
formatDuration(3600000)   // → "1 hour"

Embeds

Prebuilt, consistent embed styles — no repeated boilerplate.

successEmbed('User was banned.')
errorEmbed('User not found.', 'Error')
warnEmbed('Are you sure?')
infoEmbed('Bot is online.')
loadingEmbed('Processing...')
customEmbed({ title, description, color, footer, fields })

Pagination

Interactive embed menus with buttons, built in.

await paginate(interaction, embedArray, {
  timeout: 60000,   // ms before buttons disable (default: 60s)
  ephemeral: false,
});

chunkArray(array, 10)  // Split any array into pages of 10.

Formatters

truncate('long text...', 50)
titleCase('hello world')            // → "Hello World"
formatNumber(1500000)               // → "1,500,000"
formatBytes(2048000)                // → "1.95 MB"
discordTimestamp(new Date(), 'R')   // → relative Discord timestamp
codeBlock('code here', 'js')
inlineCode('text')
mention(userId)
channelMention(channelId)
roleMention(roleId)

Timestamp styles:

| Flag | Output | |------|--------| | t | 9:30 PM | | T | 9:30:00 PM | | d | 03/22/2026 | | D | March 22, 2026 | | f | March 22, 2026 9:30 PM | | F | Sunday, March 22, 2026 9:30 PM | | R | 3 hours ago |


Validators

isValidId('822374428541190155')
isValidUrl('https://example.com')
isImageUrl('https://x.com/img.png')
isValidHex('#FF5733')
hexToInt('#FF5733')                        // → 16734003
hasPermissions(member, [PermissionFlagsBits.BanMembers])
getMissingPermissions(member, perms)       // → array of missing perm names
isInRange('hello', 1, 100)
inNumericRange(50, 1, 100)

Permissions

isOwner(member)
isAdmin(member)
isModerator(member)
botHasChannelPerm(channel, perm)
botMissingChannelPerms(channel, perms)

Time

timeAgo(date)
accountAge(user)
memberAge(member)
shortDate(date)        // → "22/03/2026"
fullDate(date)         // → "22 March 2026 at 09:30"
addDuration(date, ms)
toUnix(date)

Cooldowns & Errors

const cooldowns = new CooldownManager();

const { onCooldown, remaining } = cooldowns.check('imagine', userId, 10000);
if (onCooldown) return interaction.reply({
  embeds: [errorEmbed(`Try again in ${remaining / 1000}s.`)]
});

Custom error classes:

throw new PermissionError();
throw new UserNotFoundError();
throw new InvalidArgumentError('Duration must be a valid format.');
throw new CooldownError(remaining);

License

MIT — free to use in your projects.

Built by Zenith-Sosuke. Contributions and issues are welcome.