Making a Starboard
Starboards: Your premium source of memes, out of context messages, and funny quotes. Let's make one, shall we!
This is a long awaited feature, requested by many people.
Let's begin by talking about what a starboard is. This is an example taken from the Discord.js Official Server.

A starboard is a popular feature in bots that serve as a channel of messages that users of the server find funny, stupid, or both! To make a functioning starboard, we need to monitor for a reaction being added to a message, and we'll do this with the messageReactionAdd and messageReactionRemove events.
So, let's begin!
In this block, we just do some simple setup for later on. For ease, I personally define the message object as message, but this is completely optional. Next, we grab the starboardChannel key from the guilds settings.
Then, we preform a couple of checks on the reaction and the message. First, we check if the reaction is NOT the unicode star emote. Next, we preform two checks on the message, checking to see if the user who added the reaction authored the message, if the user who sent the message is the person who reacted to it, and if the message author is a bot. If none of these checks return true, we're good to move on.
Now, this next block may look real complex, but it really isn't. Let's break it down.
First, we declare 6 variables here, fetch, stars, star, foundStar, image, and embed. fetch will fetch the last 100 messages in the starboard channel, stars attempts to find an embed who's footer ends with the message's id.
Next, we'll start an if statement for if there is already an embed in the starboard channel for this message, and we also define our final 4 variables. star is a simple regex to check how many stars the embed already has, foundStar allows us to use the color of the pre-existing embed, image checks if there is anything attached to the message, and embed is our new embed!
We also use a function that hasn't been talked about yet, and that is this.extension. It checks the message to see if it has any images. You'll see that later, as it's not too important.
I told you it wasn't that complicated. Let's keep going.
Now, if you were to just use the code above, your starboard would only function if there was already a message in the starboard channel. Let's take care of that.
Here we add an if statement that mimics and is placed after the previous block, but this time manually setting the color of the embed, and also manually setting the amount of stars the embed will have.
Now, if you've been following along exactly, you have a working starboard! But if you like a TL;DR, here ya go.
So, all that code up there is only for if a reaction is added. Now, we'll handle if a reaction is removed.
Here, we very closely mimic the messageReactionAdd event, only this time we'll subtract 1 from the total amount of stars that are on the embed.'
There's only a slight difference between the messageReactionAdd and the messageReactionRemove event, and that is the messageReactionAdd event fires when a reaction is added, and the messageReactionRemove event fires when a reaction is removed.
Here's the finalized code block for the messageReactionRemove event.
Last updated