I've been using the same reaction role code in my Discord bot for a few months now, however suddenly for the past few days, the bot will not give anyone any roles. I don't know what's wrong. My bot has permissions and I am not given back any sort of error messages. Here is my code for adding and removing a role.
client.on('messageReactionAdd', async (reaction, user) => {
if (reaction.message.partial) await reaction.message.fetch();
if (user.bot) return;
if (!reaction.message.guild) return;
if (reaction.message.channel.id === '741419143315587072') {
if (reaction.emoji.name === 'Mario1') {
await reaction.message.guild.members.cache
.get(user.id)
.roles.add('756305200414720022');
}
}
});
client.on('messageReactionRemove', async (reaction, user) => {
if (reaction.message.partial) await reaction.message.fetch();
if (user.bot) return;
if (!reaction.message.guild) return;
if (reaction.message.channel.id === '741419143315587072') {
if (reaction.emoji.name === 'Mario1') {
await reaction.message.guild.members.cache
.get(user.id)
.roles.remove('756305200414720022');
}
}
});
Partials
is defined here.
const client = new Discord.Client({ partials: ["MESSAGE", "CHANNEL", "REACTION"] });
And here is the message I want people to react to for the role.
const Discord = require('discord.js');
module.exports.run = async (client, message, args) => {
if (!message.member.hasPermission('ADMINISTRATOR')) {
return message.reply(
'you lack sufficiant permissions to execute this command.'
);
}
let embed = new Discord.MessageEmbed()
.setTitle('Fighters 1-18')
.setColor('#cf200a');
let msgEmbed = await message.channel.send(embed);
msgEmbed.react('695364267494342718'); //Mario
};
module.exports.config = {
name: '1-18',
description:
'Sends a message and reacts to it with all the fighters from numbers 1-18.',
usage: '!1-18',
accessableby: 'Moderators',
aliases: [],
};
This is a practical example, so you can modify the details, add a conditional format or other stuff.
//Call External Required Libraries
const Discord = require('discord.js');
//Create a Discord Client Object
const asilem = new Discord.Client({ partials: ['MESSAGE', 'CHANNEL', 'REACTION'] });
//Call Developer Required Libraries
const { token, prefix } = require('./package.json'); // Taking token from configJson
//Launch the client and must be executed one time
asilem.once('ready', () => {
console.log('Ready!');
});
//Get App Token from config.json file
asilem.login(token);
asilem.on('messageReactionAdd', async (reaction, user) => {
// When we receive a reaction we check if the reaction is partial or not
if (reaction.partial) {
// If the message this reaction belongs to was removed the fetching might
result in an API error, which we need to handle
try {
await reaction.fetch();
} catch (error) {
console.error('Something went wrong when fetching the message: ', error);
// Return as `reaction.message.author` may be undefined/null
return;
}
}
// Assign role with reaction
reaction.message.guild.members.cache.get(user.id).roles.add('760324295674298378');
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.