-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.json
57 lines (45 loc) · 4 KB
/
bot.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Require json file.
const emojis = require('./emojis.json');
// Define our function.
async function list(listMsg, page, increment) {
const entries = Object.entries(emojis);
// Set up base embed.
var embed = new Discord.RichEmbed()
.setColor(1056085)
.setTitle('**Server Emojis**')
.setDescription(`Page **${page}** of ${Math.ceil(entries.length/increment)}`)
.setFooter('Dz Gamers Community', 'https://cdn.discordapp.com/icons/469276415746113568/f86e89f362f1df6dc1f996818ef49e7a.png?size=1024')
.setTimestamp(listMsg ? listMsg.createdAt : undefined);
// Add fields to embed.
const emojiField = [];
const stringField = [];
for (let [emoji, string] of entries.slice((page - 1) * increment, (page * increment) + 1)) {
emojiField.push(emoji);
stringField.push(string);
}
embed.addField('Emoji:', emojiField.join('\n'), true);
embed.addField('String:', stringField.join('\n'), true);
// Edit/send embed.
if (listMsg) await listMsg.edit(embed);
else listMsg = await message.channel.send(embed);
// Set up page reactions.
const lFilter = (reaction, user) => reaction.emoji.name === '◀' && page !== 1 && user.id === message.author.id;
const lCollector = listMsg.createReactionCollector(lFilter, { max: 1 });
lCollector.on('collect', async () => {
rCollector.stop();
await listMsg.clearReactions();
list(listMsg, page - 1, increment);
});
const rFilter = (reaction, user) => reaction.emoji.name === '▶' && entries.length > page * increment && user.id === message.author.id;
const rCollector = listMsg.createReactionCollector(rFilter, { max: 1 });
rCollector.on('collect', async () => {
lCollector.stop();
await listMsg.clearReactions();
list(listMsg, page + 1, increment);
});
if (page !== 1) await listMsg.react('◀');
if (entries.length > page * increment) await listMsg.react('▶');
}
// Send the list; page 1, and 5 shown on each page.
list(undefined, 1, 5)
.catch(console.error);