-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
67 lines (56 loc) · 2.12 KB
/
index.js
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
58
59
60
61
62
63
64
65
66
67
import { Client, GatewayIntentBits } from "discord.js";
import dotenv from "dotenv";
dotenv.config();
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.MessageContent,
],
});
// Add additional roles as needed
const ROLES = ['User'];
// Add additional channels as needed
const CHANNELS = ['general'];
client.login(process.env.AUTHORIZATION_TOKEN);
client.on("interactionCreate", async interaction => {
if (!interaction.isCommand()) return;
const { commandName } = interaction;
if (commandName === 'ping') {
interaction.reply("Pong!");
} else if (commandName === 'clean-reactions') {
if (!interaction.member.permissions.has('ADMINISTRATOR')) {
return interaction.reply('You do not have permission to use this command.');
}
await interaction.deferReply();
const channel = interaction.options.getChannel('channel');
if (!CHANNELS.includes(channel.name)) {
return interaction.followUp(`This command is not enabled for the ${channel.name} channel.`);
}
const messages = await channel.messages.fetch({ limit: 100 });
for (const message of messages.values()) {
await message.fetch();
for (const reaction of message.reactions.cache.values()) {
await reaction.users.fetch();
for (const user of reaction.users.cache.values()) {
if (!user.bot) {
const member = await message.guild.members.fetch(user.id);
if (ROLES.some(roleName => member.roles.cache.some(role => role.name === roleName))) {
await reaction.users.remove(user.id);
}
}
}
}
}
interaction.followUp(`Reactions cleaned in ${channel.name}`);
}
});
client.on('messageReactionAdd', async (reaction, user) => {
if (CHANNELS.includes(reaction.message.channel.name) && !user.bot) {
const member = await reaction.message.guild.members.fetch(user.id);
if (ROLES.some(roleName => member.roles.cache.some(role => role.name === roleName))) {
await reaction.users.remove(user.id);
}
}
});