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 🙏

© 2024 – Pkg Stats / Ryan Hefner

reaction-core

v2.4.0

Published

Add snazzy menus to your bot's messages using Discord's reaction system.

Downloads

17

Readme

reaction-core

This is an NPM module that allows you to create snazzy little menus on your bot's messages using reactions. ~~Note that currently only default Discord emotes will work.~~

Now with support for custom emoji! You must provide only the numerical part of the emoji ID as the Button's emoji in order for this to work.

Development

Currently reaction-core is being maintained by Discord user Mundane#9887. There is still some additional functionality to add, and suggestions and bug reports are welcome and encouraged.

Basic Usage

See example.js for the complete code.

Firstly, grab the module and make a handler. The handler will handle all the incoming emoji reactions, as well as save and load past menus.

const RC = require('reaction-core')
const handler = new RC.Handler()

Secondly, handle reactions being made:

client.on('messageReactionAdd', (messageReaction, user) => handler.handle(messageReaction, user))

That's all you have to do to ensure all your menus will function correctly. To actually make a menu, a few more steps are needed.

A menu is basically a message with a collection of emoji that execute specific callbacks, known as buttons. One menu can have up to 20 buttons; this is Discord's limit of the amount of reactions you can have on one message. You could, however, have a button that changes all the buttons (changing page, if you like), effectively making the limit useless. Below is example code for creating a simple menu that just changes the colour of the embed of the menu. There are endless possibilities to what it can actually do - some uses I know of are a jukebox and a user moderation menu where each button is a different moderation action. The code for the buttons is in exButtons.js, so that only code relevant to the module is in the main example file.

Note that in the following code, I use an array of object literals as my buttons. reaction-core also exports a Button class that can be used to create buttons.

First, let's create the menu, passing it the text to display and it's buttons.

let changeColour = new RC.Menu(example.embed, example.buttons, example.options)

The options object currently owner supports setting an 'owner', whereby the specified user is the only one who can interact with the menu, specified by ID. An example options object is

{
  owner: '216399535390326794'
}

Next, register the menu to the handler.

handler.addMenus(changeColour)

Like the previous code, you can specify an infinite number of menus at once.

Finally, send the menu. You can do this however you want; I did it in an example command ran by doing rc!test:

client.on('message', message => {
  if (!message.author.bot && message.content === 'rc!test') {
    message.channel.sendMenu(changeColour)
  }
})

And that's it! The menu will get sent, and clicking the buttons changes the colour of the embed. example.js will compile and run if you give it a valid bot token at the bottom of the file.

To-Do:

  • [ ] Better error-checking and reporting.
  • [ ] Finish this list.