diff --git a/events/ratingReact.js b/events/ratingReact.js new file mode 100644 index 0000000..1f7b9d6 --- /dev/null +++ b/events/ratingReact.js @@ -0,0 +1,43 @@ +const { Events, Partials } = require('discord.js'); + +module.exports = { + name: Events.MessageReactionAdd, + async execute(reaction, user) { + if (reaction.partial) { + try { + await reaction.fetch(); + } catch (error) { + console.error('Reacted message can not be fecthed:', error); + return; + } + } + + let channelWhitelist = [ + '1220653860251762688', //musik hier + '1221748800671191050', //track der woche + '1220685344341757952', //playlists + '1159103323018891264' //test + ]; + + if(!channelWhitelist.includes(reaction.message.channel.id)) { + return; + } + + let title = 'Unknown'; + if(reaction.message.author.id == "816228963285860373") { + title = reaction.message.embeds[0].title; + } else { + console.log(`${reaction.message.author}'s message "${reaction.message.content}" gained a reaction!`); + title = reaction.message.content.split("\n")[0]; + } + + if(title.startsWith('https://')) { + title = `<${title}>`; + } + + await reaction.message.channel.send({ + content: `${user.displayName} rated **${title}** with ${reaction._emoji.toString()}`, + reply: { messageReference: reaction.message.id } + }); + }, +}; \ No newline at end of file diff --git a/main.js b/main.js index cb671a1..6d5dbef 100644 --- a/main.js +++ b/main.js @@ -1,10 +1,11 @@ const fs = require('node:fs'); const path = require('node:path'); -const { Client, Collection, Events, GatewayIntentBits, Options } = require('discord.js'); +const { Client, Collection, Events, GatewayIntentBits, Options, Partials } = require('discord.js'); const { token } = require('./config.json'); const client = new Client({ - intents: [GatewayIntentBits.Guilds, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildPresences], + intents: [GatewayIntentBits.Guilds, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildPresences, GatewayIntentBits.GuildMessageReactions], + partials: [Partials.Message, Partials.Channel, Partials.Reaction], sweepers: { ...Options.DefaultSweeperSettings, reactions: { interval: 300, filter: () => () => { return true } }