Skip to content

Commit 7c1dba2

Browse files
committed
Starboard Bot
1 parent 644af5d commit 7c1dba2

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

Starboard-Bot/package.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "Starboard-Bot",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "ISC",
12+
"dependencies": {
13+
"discord.js": "^12.1.1",
14+
"dotenv": "^8.2.0"
15+
}
16+
}

Starboard-Bot/src/bot.js

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
require('dotenv').config();
2+
const { Client, MessageEmbed } = require('discord.js');
3+
const client = new Client({ partials: ['MESSAGE', 'REACTION']});
4+
client.login(process.env.BOT_TOKEN);
5+
6+
client.on('ready', () => {
7+
console.log(`${client.user.tag} has logged in.`);
8+
});
9+
10+
client.on('messageReactionAdd', async (reaction, user) => {
11+
const handleStarboard = async () => {
12+
const starboard = client.channels.cache.find(channel => channel.name.toLowerCase() === 'starboard');
13+
const msgs = await starboard.messages.fetch({ limit: 100 });
14+
const existingMsg = msgs.find(msg =>
15+
msg.embeds.length === 1 ?
16+
(msg.embeds[0].footer.text.startsWith(reaction.message.id) ? true : false) : false);
17+
if(existingMsg) existingMsg.edit(`${reaction.count} - 🌟`);
18+
else {
19+
const embed = new MessageEmbed()
20+
.setAuthor(reaction.message.author.tag, reaction.message.author.displayAvatarURL())
21+
.addField('Url', reaction.message.url)
22+
.setDescription(reaction.message.content)
23+
.setFooter(reaction.message.id + ' - ' + new Date(reaction.message.createdTimestamp));
24+
if(starboard)
25+
starboard.send('1 - 🌟', embed);
26+
}
27+
}
28+
if(reaction.emoji.name === '🌟') {
29+
if(reaction.message.channel.name.toLowerCase() === 'starboard') return;
30+
if(reaction.message.partial) {
31+
await reaction.fetch();
32+
await reaction.message.fetch();
33+
handleStarboard();
34+
}
35+
else
36+
handleStarboard();
37+
}
38+
});
39+
40+
client.on('messageReactionRemove', async (reaction, user) => {
41+
const handleStarboard = async () => {
42+
const starboard = client.channels.cache.find(channel => channel.name.toLowerCase() === 'starboard');
43+
const msgs = await starboard.messages.fetch({ limit: 100 });
44+
const existingMsg = msgs.find(msg =>
45+
msg.embeds.length === 1 ?
46+
(msg.embeds[0].footer.text.startsWith(reaction.message.id) ? true : false) : false);
47+
if(existingMsg) {
48+
if(reaction.count === 0)
49+
existingMsg.delete({ timeout: 2500 });
50+
else
51+
existingMsg.edit(`${reaction.count} - 🌟`)
52+
};
53+
}
54+
if(reaction.emoji.name === '🌟') {
55+
if(reaction.message.channel.name.toLowerCase() === 'starboard') return;
56+
if(reaction.message.partial) {
57+
await reaction.fetch();
58+
await reaction.message.fetch();
59+
handleStarboard();
60+
}
61+
else
62+
handleStarboard();
63+
}
64+
});

0 commit comments

Comments
 (0)