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

discord.js-menu-fork

v1.0.0

Published

▶ Automatically create Discord.js embed menus with reactions and multiple completely customisable pages.

Downloads

2

Readme

logo

Installation

In your project directory:

npm install discord.js-menu

In your code file:

const { Menu } = require('discord.js-menu');

It's as easy as that!

Examples

I wanted to make menus as easy as possible to create - it can be quite daunting at first, but I don't think it's too bad! Creating and sending a message is as easy as importing the Menu class and instantiating one. For this example, let's presume we're trying to show the user a help menu, with a list of commands, or similar.

const { Client, MessageEmbed } = require('discord.js');
const { Menu } = require('discord.js-menu');
const client = new Client();

client.on('message', message => {
    if (message.content == "help") {
        // Creating the menu like this will automatically send it and handle reactions - basically everything.
        // I recommend you import this big array from a secondary file to clean up your code - your choice though.
        new Menu(message.channel, message.author.id, [
            {
                name: "main",
                content: new MessageEmbed({
                    title: "Help",
                    description: "Commands list:",
                    fields: [
                        {
                            name: "command1",
                            value: "this command does stuff"
                        }
                    ]
                }),
                reactions: {
                    "⏹": "stop",
                    "▶": "next",
                    "⚙": "otherPage"
                }
            },
            {
                name: "otherPage",
                content: new MessageEmbed({
                    title: "More Help!",
                    description: "Here are some more commands!",
                    fields: [
                        {
                            name: "You get the idea.",
                            value: "You can create as many of these pages as you like."
                            // (Each page can only have 20 reactions, though. Discord's fault.)
                        }
                    ]
                }),
                reactions: {
                    "⏹": "stop",
                    "◀": "previous",
                    "1️⃣": "first"
                }
            }
        ]);
    }
});


client.login(...);

This is a relatively small menu, at only 2 pages. You can theoretically have as many pages as you want - I've tested it with up to 10, but you can totally go higher.

Creating the menu, in-depth

new Menu(channel, userID, pages)

Channel and userID are both relatively obvious - a channel to send the message to, and the ID of the user you wish to let control the menu - the pages array is a little more complex, though, as you might've seen.
pages is an array of objects; each object is it's own page in the menu.
Every page has three items: a name, which is used as a destination for your reactions, the content (a MessageEmbed), and a set of reactions for that page.
Each reaction is an emoji, and its value is a destination you have set. Every page's name is a destination. There are also 5 other destinations that serve various functions.

first - Goes to the first page in the array.
last - Goes to the last page in the array.
previous - Goes to the previous page in the array.
next - Goes to the next page in the array.
stop - Removes the reactions and deletes the menu message.

Note that calling one of your pages one of these will still technically work - the page would still be accessible using these destinations, ironically - but you wouldn't be able to directly link to it.

Acknowledgements

This project was heavily inspired by Juby210's discord.js-reaction-menu. It's a great project, and I was originally using it, but in the end, creating my own version seemed more worthwhile. Much respect to Juby210, though!