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

@xenon-devs/discordjs-reaction-menu

v1.0.4

Published

A simple, modern and easy to use reaction menu for discord.js

Downloads

15

Readme

DiscordJS Reaction Menu

A simple, modern and easy to use reaction menu for discord.js.

NPM

Table of Contents

Installation

Install using npm:

npm install @xenon-devs/discordjs-reaction-menu

Or using yarn:

yarn add @xenon-devs/discordjs-reaction-menu

Usage

This package exports a single class, ReactionMenu. Typescript typings are also included.

Usage:

const { ReactionMenu } = require('@xenon-devs/discordjs-reaction-menu');

const menu = new ReactionMenu({ // Initialize
  pages,
  channel,
  timeout
})

menu.start([user1Id, user2Id]); // Start

See more examples.

ReactionMenu

This is the base class. See usage.

Constructor: ReactionMenu(pages, channel, timeout = 60, customControlsEmojis = ReactionMenu.ControlsEmojiDefaults)

Arguments:

  1. pages: An array of IMenuPages.
  2. channel: A TextChannel or DMChannel to send the menu in.
  3. timeout: The time (in seconds) after which the menu stops working. (Default: 60)
  4. customControlsEmojis: Optional custom controls emojis ie the next and back buttons. (Default: see ControlsEmojiDefaults in the ReactionMenu properties below)

Properties:

  • controlsEmojis: IControlsEmojis.
  • menuMessage: The message which is sent with the menu embed.
  • reactionCollector: The ReactionCollector associated with the menu.
  • listenTo: An array of User.id. Only these users can change the menu pages. Set in the start method below.
  • currentPaage: The 0-indexed number of the current page, that is, it's index in the pages property.
  • timeout: The timeout in seconds after which the menu stops working.
  • static ControlsEmojiDefaults: The defaults for the controlsEmojis property above. It's value is:
    {
      first: '⏮️',
      next: '➡️',
      back: '⬅️',
      last: '⏭️'
    }

Methods:

  • start(listenTo, startPage): Sends the menu embed and starts the menu.

    • listenTo: An array of User.id. Only these users can change the menu pages.
    • startPage: The 0-indexed page at which the menu starts. (Default: 0)
  • displayPage(pageNumber): Display a page manually in code (apart from the reactions).

    • pageNumber: 0-indexed number of the page to be displayed.
  • stop(): Stops the menu manually, before the timeout.

IMenuPage

An object of the format:

{
  pageEmbed: embed, // The embed for this page.
  customReaction?: string // Optional custom emoji to jump to this page.
}

Properties:

  • pageEmbed: MessageEmbed for this page.
  • customReaction: Optional emoji string in the menu to jump to this page.

IControlsEmojis

An object of the format:

{
  first: string, // Emoji to jump to the first page
  next: string, // Emoji to go to the next page
  back: string, // Emoji to go to the previous page
  last: string // Emoji to jump to the last page
}

Default: See ControlsEmojiDefaults property in ReactionMenu.

Examples

  1. Simplest Reaction Menu.
const { ReactionMenu } = require('@xenon-devs/discordjs-reaction-menu');
const { MessageEmbed } = require('discord.js');

const menu = new ReactionMenu(
  [
    {
      pageEmbed: new MessageEmbed().setTitle('Page 1').setDescription('Click on emojis below to navigate.')
    },
    {
      pageEmbed: new MessageEmbed().setTitle('Page 2')
    }
    },
    {
      pageEmbed: new MessageEmbed().setTitle('Page 3')
    }
  ],
  msg.channel // Get from an on('message') event listener.
)

menu.start([msg.author.id]) // Get from an on('message') event listener.
  1. Custom Controls Emojis.
const { ReactionMenu } = require('@xenon-devs/discordjs-reaction-menu');
const { MessageEmbed } = require('discord.js');

const menu = new ReactionMenu(
  [
    {
      pageEmbed: new MessageEmbed().setTitle('Page 1').setDescription('Click on emojis below to navigate.')
    },
    {
      pageEmbed: new MessageEmbed().setTitle('Page 2')
    }
    },
    {
      pageEmbed: new MessageEmbed().setTitle('Page 3')
    }
  ],
  msg.channel, // Get from an on('message') event listener.
  60, // 60 seconds
  {
    next: '▶️',
    first: '🏠',
    back: '◀️',
    last: '📄'
  }
)

menu.start([msg.author.id]) // Get from an on('message') event listener.
  1. Custom Page Jump Emojis.
const { ReactionMenu } = require('@xenon-devs/discordjs-reaction-menu');
const { MessageEmbed } = require('discord.js');

const menu = new ReactionMenu(
  [
    {
      pageEmbed: new MessageEmbed().setTitle('Page 1').setDescription('Click on emojis below to navigate.'),
      customReaction: '🏠' // Click on this emoji to jump to this page
    },
    {
      pageEmbed: new MessageEmbed().setTitle('Page 2 | Cats'),
      customReaction: '🐱' // Click on this emoji to jump to this page
    }
    },
    {
      pageEmbed: new MessageEmbed().setTitle('Page 3 | Dogs'),
      customReaction: '🐶' // Click on this emoji to jump to this page
    }
  ],
  msg.channel // Get from an on('message') event listener.
)

menu.start([msg.author.id]) // Get from an on('message') event listener.