Reactions not working after restart #122
-
So I've updated my bot to discordjs v14 using nodejs, the functions and everything works the same, nothing has changed and for some reason with 3.1.0 of discordjs-reaction-role whenever I react to an emoji it doesn't apply a role UNLESS I refresh the message, then it works as normal. Now, this would be fine, but my bot goes through normal restarts every once and a while and afterwards breaks reactions, unless I refresh the message again manually via a command. Here is a breakdown of what I mean; So, I have all of the variables set in a config files as such, config.json: "reactions": {
"channelID" : {
"rules":"1005476785275817985",
"assignments":"1005489898582720542"
},
"msgID" : {
"rules":"1005482170363686957",
"assignments":"1005515236658389042"
},
"role" : {
"omega":"1005476872886431796",
"refused":"1005485396819456040"
},
"emoji" : {
"omega":"✅",
"refused":"❌"
}
} Then I have one of my event files for client.once('ready'), reactions.js: const { ReactionRole } = require('discordjs-reaction-role');
const { reactions } = require('../config.json');
module.exports = {
name: 'ready',
once: true, // <------ I have tried both 'true' and 'false'; Made no difference
async execute(client) {
new ReactionRole(client, [
{ messageId: reactions.msgID.rules, reaction: reactions.emoji.omega, roleId: reactions.role.omega },
{ messageId: reactions.msgID.rules, reaction: reactions.emoji.refused, roleId: reactions.role.refused },
]);
console.log('Reactions Loaded');
},
}; So this points to a message in my const { EmbedBuilder } = require('discord.js');
const { reactions, guildID } = require('../config.json');
module.exports = {
name: 'messageCreate',
once: false,
async execute(message) {
if (message.content == '/rules') {
const title = new EmbedBuilder()
.setColor('#C27C0E')
.setTitle('ETC.');
const general = new EmbedBuilder()
.setColor('#C27C0E')
.setTitle('**General Rules**')
.setDescription(`ETC.`);
const voice = new EmbedBuilder()
.setColor('#C27C0E')
.setTitle('**Voice Chat Rules**')
.setDescription(`ETC.`);
const bot = new EmbedBuilder()
.setColor('#C27C0E')
.setTitle('**Bot Rules & Commands**')
.setDescription(`ETC.`);
const footer = new EmbedBuilder()
.setColor('#C27C0E')
.setDescription(`ETC.`);
const rulesmessage = new EmbedBuilder()
.setColor('#e42643')
.setTitle('Rules and conditions')
.setDescription('ETC.');
message.channel.bulkDelete(1, true);
const g = message.client.guilds.cache.get(guildID);
const c = g.channels.cache.find(chn => chn.id === reactions.channelID.rules);
c.messages.fetch(reactions.msgID.rules).then(msg => {
msg.edit({ embeds: [title, general, voice, bot, footer, rulesmessage] });
msg.react(reactions.emoji.omega);
msg.react(reactions.emoji.refused);
}).catch(err => {
console.error(err);
});
}
},
}; Reactions use to work as normal, even after restart but now after rebuilding the bot for v14 they no longer work unless I run that command above to refresh the message. I'm kinda at a loss, I could have the bot auto run the commands (I have multiple channels with reactionroles in them) itself whenever it restarts, but would rather it not have to be that way. Did I mess something up or could it be an issue with your library? EDIT const { reactions } = require('../config.json');
module.exports = {
name: 'ready',
once: true,
async execute(client) {
client.channels.fetch(reactions.channelID.rules).then(channel => {channel.send('/rules');});
},
}; But would still like to hear your input on the situation |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
This is one of the surprises that I got while updating the bot. I have a staging server to test my bot. I always run one of the examples, react to a message, check if I get the role, unreact to the message, check if it removes the role. First test I do after updating to Discord.js 14, this exact issue happening. It turns out that Discord.js is now more strict with data that is not in the bot cache, and it will not deliver events for messages that existed before the bot restarts unless you subscribe to the partials. Check if you have the partials for Message and Reaction set when creating the discordjs Client. Something like: const bot = new Client({
partials: ["MESSAGES", "REACTION"],
// ...
}) Also, if the partials were already set, there is an undocumented debug mode that I added today when I had this issue and did not remove just in case. If you run the application with the If you run your bot using a terminal or console, set the variable REACTION_DEBUG=1 before you run the command you use to start the bot, using export on Linux or Mac, or set on Windows. Or just add the following JavaScript code before calling process.env.REACTION_DEBUG = 1; Then whenever a reaction is caught by the library (regardless if it is one in the configuration or not), something will be logged with information. Use this to debug that at least it is receiving the reaction. If you are receiving the numbers but it is not adding the role, something may be wrong with my update. |
Beta Was this translation helpful? Give feedback.
This is one of the surprises that I got while updating the bot. I have a staging server to test my bot. I always run one of the examples, react to a message, check if I get the role, unreact to the message, check if it removes the role.
First test I do after updating to Discord.js 14, this exact issue happening. It turns out that Discord.js is now more strict with data that is not in the bot cache, and it will not deliver events for messages that existed before the bot restarts unless you subscribe to the partials.
Check if you have the partials for Message and Reaction set when creating the discordjs Client. Something like: