If 5 people react to a message with 🌟then the bot will copy the message and post it as an embed into the #starboard channel. (Enter your own ID numbers at the top)
// authenticates you with the API standard library
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const { DateTime } = require('luxon')
//Made by MagicalMongoose#1111 and Kangabru
let offmbr = ''; //Role to confirm starboards
let starChnl = ''; //Channel to post starboards
let validEmoji = '🌟'; //Emoji to react with
let guild_id = ''; //Guild of the channel (only works in 1)
let botId = ''; //ID of the bot running this script
const triggerCount = 5;
// Is this the right emoji?
if (context.params.event.emoji.name !== validEmoji) return
// We use the bot's reaction to prevent mutliple triggers.
// Get the existing reactions and check if the bot has reacted.
let reactions = await lib.discord.channels['@0.1.2'].messages.reactions.list({
emoji: validEmoji,
message_id: `${context.params.event.message_id}`,
channel_id: `${context.params.event.channel_id}`,
});
//Checks if the bot has already reacted
const botHasReacted = !!reactions.find(x => x.id === botId)
//Get message object data
let msg = await lib.discord.channels['@0.1.2'].messages.retrieve({
message_id: `${context.params.event.message_id}`,
channel_id: `${context.params.event.channel_id}`,
});
//Set message link and embed time
let msgLink = `https://discord.com/channels/${guild_id}/${msg.channel_id}/${msg.id}`;
const dt = DateTime.fromISO(msg.timestamp).setZone("America/Chicago").setLocale('en-US');
let time = dt.toLocaleString(DateTime.DATETIME_MED);
//Get user pfp
let user = await lib.discord.users['@0.1.4'].retrieve({
user_id: `${msg.author.id}`
});
//Count the stars
let counter = await lib.discord.channels['@0.1.2'].messages.reactions.list({
emoji: validEmoji,
message_id: `${msg.id}`,
channel_id: `${msg.channel_id}`,
limit: triggerCount
});
//If official member reacts, with valid emoji, and reaches minStars,
//and not already selfstarred, then do stuff
if (!botHasReacted
&& context.params.event.member.roles.includes(offmbr)
&& reactions.length >= triggerCount)
{
//React with star so it doesn't repeat
await lib.discord.channels['@0.1.2'].messages.reactions.create({
emoji: validEmoji,
message_id: `${msg.id}`,
channel_id: `${msg.channel_id}`
});
//Send embed to #starboard
await lib.discord.channels['@0.1.2'].messages.create({
channel_id: `${starChnl}`,
content: '',
embed:
{
author:
{
name: "🌟Link to original🌟",
url: `${msgLink}`,
icon_url: `${user.avatar_url}`,
},
color: 0x33669a,
description: `From <@${msg.author.id}> at ${time}` + "\n" + msg.content
},
});
}