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-buttons

v2.1.2

Published

Send menus with buttons or list

Downloads

53

Readme

discord.js-menu-buttons

At first I would like to clarify that this package is just a modification to an already existing package discord.js-menu-reactions but since the autor of that package is unactive and the package is stuck in discord.jsV12 I made a modified version of this package that is up to date. Also some of the readme will be stripped of right from the original package since I'm too lazy to type this shit in.

Docs

Here are the docs for the module although you can see the usage below

Usage

Using this package is quite simple and simmilar to the original so if you've used Jowsey's package before you'll be familiar with this setup. In this example I'm creating a menu that has 2 pages, "page 1" and "page 2". "page 1" has two buttons one for the bot to send a message saying hello and the other to move to page 2. All of the code will be in typescript (and I highly encourage you to use it). Everything in the bot is documented in typescript so you don't have to worry about not working intelisense.

Initializing

The bot requires giving it a client variable since InteractionCollector needs it. To initialize the bot you have to execute the function named setClient

import { Client, MessageEmbed } from "discord.js";
import { Menu } from "discord.js-menu-buttons";
const client = new Client({ intents: ["GUILDS", "GUILD_MESSAGES"] });
setClient(client);

Menu

const menu = new Menu(message.channel, message.author.id, [
{
    name: "page1",
    content: new MessageEmbed().setTitle("Hello!"),
    rows: [
        new Row([
            new ButtonOption(
                {
                    customId: "thisHasToBeRandomAndDifferentFromEveryButton",
                    style: "PRIMARY",
                    label: "Button1"
                },
                (i) => {
                    i.deferUpdate();
                    console.log("Clicked button1 " + i.customId)
                }
            ),
            new ButtonOption(
                {
                    customId: "thisHasToBeRandomAndDifferentFromEveryButton1",
                    style: "PRIMARY",
                    label: "Button2"
                },
                (i) => {
                    i.deferUpdate();
                    console.log("Clicked button1 " + i.customId)
                    
                }
            )
        ], RowTypes.ButtonMenu),
        new Row([
            new MenuOption(
                {
                    label: "lbl",
                    value: "value",
                },
                (i) => {
                    i.deferUpdate();
                    console.log(i.values[0]); //value
                }
            )
        ], RowTypes.SelectMenu),
        new Row([
            new MenuOption(
                {
                    label: "label",
                    description: "description",
                    value: "val"
                },
                "page2"
            )
        ], RowTypes.SelectMenu)
    ]
},
{
    name: "page2",
    content: new MessageEmbed().setTitle("Page2"),
    rows: [
        new Row([
            new MenuOption(
                {
                    label: "label1",
                    value: "value1",
                },
                (i) => {
                    i.deferUpdate();
                    console.log(i.values[0]);
                }
            ),
            new MenuOption(
                {
                    label: "go to page1",
                    value: "value2"
                },
                "page1"
            )
        ], RowTypes.SelectMenu)
    ]
}
])
menu.start();

Special Destinations

You may have noticed I mentioned "special destinations" above.
discord.js-menu-buttons comes with 6 pre-defined destinations with specific uses.

| Destination | Function | |------------- |--------------------------------------------------------------- | | 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 reactions from the embed and stops updating the menu. | | delete | Stops the menu and deletes the message. |

Note that whilst calling a page one of these wouldn't break anything (the page would still be accessible using, ironically, the special destinations) you wouldn't be able to directly link to it.

Support

You can visit this support discord.

Acknowledgements

Major parts of this project were by Jowsey's discord.js-menu.