If 3 users react with 🌟 to a message, the bot will copy that message and post it to a channel you designate as the starboard channel once an official member confirms it. You must set the channel id on line 6 for the starboard channel and the role id of members who can confirm.
//Made by MagicalMongoose#1111 and Kangabru
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const {DateTime} = require('luxon');
const cpe = context.params.event;
let offmbr = 'CONFIRMER ROLE ID HERE'; //Role to confirm starboards
let starChnl = 'CHANNEL ID HERE'; //Channel to post starboards
let validEmoji = '🌟'; //Emoji to react with
let guild_id = cpe.guild_id;
let botId = await lib.discord.users['@0.1.4'].me.list().id;
const triggerCount = 3;
// Is this the right emoji?
if (cpe.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: cpe.message_id,
channel_id: cpe.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: cpe.message_id,
channel_id: cpe.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 &&
cpe.channel_id != starChnl &&
cpe.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 add the embed, and if it has an image add the image
function embed() {
let output = {
type: 'rich',
author: {
name: '🌟Link to original🌟',
url: msgLink,
icon_url: user.avatar_url,
},
color: 0x33669a,
description: `From <@${msg.author.id}> at ${time}` + '\n' + msg.content,
};
if (msg.attachments[0] != undefined) {
output.image = {url: `${msg.attachments[0].url}`};
}
return output;
}
//Send embed to #starboard
await lib.discord.channels['@0.1.2'].messages.create({
channel_id: starChnl,
content: '',
embed: embed(),
});
}