[英]Having issues with reaction roles in Discord.js
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.几个月来,我一直在我的 Discord 机器人中使用相同的反应角色代码,但是在过去的几天里,机器人突然不给任何人任何角色。 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. Partials
在这里定义。
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');
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.