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;
}
};
5 Replies
- What's your exact discord.js
npm list discord.js
and node node -v
version?
- Not a discord.js issue? Check out #other-js-ts.
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button!
- ✅
Marked as resolved by OPdiscord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
thanks, I checked this once again to see what I really did wrong and after comapring it seems I inserted another square bracket within my partials so it would look like
partials: [
[Partials.Message, Partials.Channel, Partials.Reaction]
],
Instead of...
partials: [
Partials.Message, Partials.Channel, Partials.Reaction
],
oh yeah, an array of arrays is probably not properly passed by the lib
^yeah haha, dum mistake by me