Discord.js Reaction Help Guide
  • Welcome
  • Before you start..
  • Stable
    • Getting Started
    • Command
    • Basic Reaction Logic (1/2)
    • Finishing Reaction Logic (2/2)
    • And we're done!
Powered by GitBook
On this page

Was this helpful?

  1. Stable

Command

The actual help command, to start the magic.

From now on, I'm omitting the surrounding code, and just providing the current code.

Lets start right here, at the help command comment..

    if (command == 'help') {
        // our help command will be here
    }

Remove the comment, as we'll start writing a few things here now. First, lets specify an object with some settings for the reaction help:

const options = {
    limit: 15 * 1000,
    min: 1,
    max: 2, // there will be 2 pages
    page: 1
}

Let me explain these..

  • limit is how long you want to wait for a reaction before timing out completely. Here, we've set it to 15 seconds, a reasonable time.

  • min is the minimum page, aka. the lowest you can go.

  • max is the maximum page, aka. the highest you can go, usually the last page.

    • Both min and max are used to set the limits for the user, so errors won't occur.

  • page is the page to start the help on, and should probably be left as 1.

Now, we can add some basic code to send an embed, and add the reactions:

// don't worry, we'll define pages next
const m = await msg.channel.send({ embed: pages[options.page] });

await m.react('⬅');
await m.react('➡');
await m.react('🗑');

Here, we're sending the first page, and adding the back, forward and delete reactions (those are, in Discord, :arrow_left:, :arrow_right: and :wastebasket:).

For watchful users, we can define pages now. For simplicity, we'll just use an object. Go to where we made the // pages comment, and replace it with this code:

const pages = {
    1: { title: ':one:', description: 'This is page one!' }, 
    2: { title: ':two:', description: 'This is page two!' }
}

These are embed objects, we're using them so we don't have to use the more complicated (in this situation) embed builder.

Now, you have pages, and these will be sent on request.

Finally, to finish the command, add this little bit of code (we'll be coding next) to start listening for reactions:

const filter = (reaction, user) => {
    return ['⬅', '➡', '🗑'].includes(reaction.emoji.name) && user.id == msg.author.id;
};

awaitReactions(msg, m, options, filter);

The filter may look complicated, but all it does is makes sure the reaction received is one we want, and that the person that reacts is who used the help command.

PreviousGetting StartedNextBasic Reaction Logic (1/2)

Last updated 6 years ago

Was this helpful?