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

unicorn-discord-bot

v0.2.4

Published

A module to create and manage a discord bot

Downloads

8

Readme

unicorn-discord-bot

A simple but robust and highly customizable Discord bot.

Installation

npm install unicorn-discord-bot

yarn install unicorn-discord-bot

Usage

const { DiscordBot, Intents } = require('unicorn-discord-bot');
const { join } = require('path');

// get all possible intents
const bits = [];
for (const key in Intents.FLAGS) {
  bits.push(Intents.FLAGS[key]);
}
const intents = new Intents(bits);

// bot options
const options = {
  clientOptions: {
    intents,
  },
  commandsDirPath: join(__dirname, 'commands'), // where your commands lives
  prefix: '+!',
  talkingToMeResponse: 'http://sayitwithcaptions.com/wp-content/uploads/2020/10/You-talkin-to-me-1.jpg',
  talkingAboutMeResponse: 'http://sayitwithcaptions.com/wp-content/uploads/2021/02/Quoi.png',
};

// create the bot
const bot = new DiscordBot(options);

// start the bot
bot.start();

Enviorment Variables

As this package is using dotenv to load the .env file, you can set the following minimal enviorment variables:

PUBLIC_KEY=""
APP_ID=""
BOT_TOKEN=""
CLIENT_ID=""
DEV_MODE=on
GUILD_ID=""

Note: The DEV_MODE on is useful to test the commands, since when it is not in dev mode, Discord performs a command cache which can be very long. As long as you use your bot in a dev environment and onto only one Discord server (aka guild), it is pretty useful to keep the DEV_MODE on.

Commands

You can add commands to the bot by adding them to the commandsDirPath option. Or add them before it starts with the addCommand method of the DiscordBot class.

Commands can be triggered via:

  • slash commands like /ping
  • prefixed commands like !ping (you can set the bot prefix with the prefix option of the DiscordBot class)
  • mentions like @bot ping (the command name can be everywhere in the message ; supports multiple commands)

By default, all commands can be triggered via these three behaviors. You can change this behavior by setting the isSlashCommand option of the DiscordBot class to false. if isSlashCommand is false, the bot will only accept commands prefixed with the bot prefix and "mentions" calls only, for this command.

Here is a simple example of a ping command:

const { Command } = require('unicorn-discord-bot');

const ping = new Command({
  command: 'ping',
  description: 'Replies with pong!',
  handler: async (interaction) => {
    await interaction.reply({ content: 'pong!', ephemeral: true });
  },
});

module.exports = ping.me;

Buttons handling

Each command can declare a buttons handler. This handler will be called when the user clicks on a button in the command's message. To do so, you need to add the buttonsHandler option to the command.

SoundManager

This bot is able to join a vocal channel and play sounds into it. To do so, you can import the SoundManager class and use it to create a sound manager. This implementation can natively play webm formatted files.

Here is an example of a play sound command using the sound manager:

const { Command, SoundManager } = require('unicorn-discord-bot');
const { join } = require('path');

const defaultVolumes = {
  campfire: 0.3,
  cave: 0.1,
  epicCombat: 0.08,
  hive: 0.08,
  magicForest: 0.2,
  nobleParty: 0.05,
  ritual: 0.035,
  riverside: 0.08,
  antre: 0.03,
};
const filesDirPath = join(__dirname, 'dnd', 'ambiances');

const soundManagerOptions = {
  channelName: 'DnD',
  defaultVolumes,
  filesDirPath,
};

let soundManager;

const getSoundManager = async (interaction) => {
  if (!soundManager) {
    soundManager = new SoundManager({ ...soundManagerOptions, interaction });
    await soundManager.init();
  }
};

const handler = async (interaction) => {
  await getSoundManager(interaction);
  await interaction.reply({ content: 'Quel son jouer ?', components: await soundManager.menu() });
};

const buttonHandler = async (interaction) => {
  if (interaction.customId.lastIndexOf('playsound-', 0) !== 0) {
    return 0;
  }

  const soundName = interaction.customId.replace(/^(playsound-)/, '');

  await getSoundManager(interaction);

  try {
    await soundManager.playOrStop(interaction, soundName);
  } catch (error) {
    console.error(error.message);
  }

  return 1;
};

const playsound = new Command({
  command: 'playsound',
  description: 'play a sound in a voice channel',
  handler,
  buttonHandler,
  requiredRoles: ['GM'],
  requiredRolesErrorMessage: 'https://c.tenor.com/nw2rtAIe1UQAAAAd/power-lord-of-the-rings.gif',
});

module.exports = playsound.me;