anti
anti
DIAdiscord.js - Imagine an app
Created by anti on 11/13/2023 in #djs-questions
How to handle previous instances?
I'm currently making a code that adds a role when the user reacts to a message in a specific channel. However, I wanted to make it so that every time I restart the client and make a new instance, the messages from that specific channel can still trigger the event messageReactionAdd. After looking around, I found out about partials. I am now trying to implementing this method into my code but I'm having a difficult time understanding it and trying to get it to work. module.exports = async ( message, reaction, client ) => { console.log(reaction); try { //fetch partial message if it's uncached if (message.message.partial) { await message.message.fetch(); } if (reaction.partial) { await reaction.fetch(); } const channelId = message.message.channelId; const guild = client.guilds.cache.get(message.message.guildId); if (!guild) { console.error(Guild ${message.message.guildId} not found); return; } const member = message.message.guild.members.cache.get(reaction.id) const role = member.roles.cache; if (channelId === '852196626138267698') { if (!(role.some(role => role.name === 'based'))) { await member.roles.add('852586777188237413'); console.log('added'); } } } catch (error) { console.error('Error: ', error); return; } };
6 replies
DIAdiscord.js - Imagine an app
Created by anti on 10/18/2023 in #djs-questions
How to properly get channel ID?
Hello, all I really want to do is to get the channel ID, but I'm struggling to do so as it prints out as undefined. module.exports = async ( interaction, client, member) => { const channelID = interaction.channel?.id; console.log(channelID); /if (channel.id === '852196626138267698') { console.log('works!'); }/ }
31 replies