[英]I'm trying to make reaction roles using my own discord bot but for some reason it doesn't add the role even though it adds the reactions
I'm trying to make a discord bot that adds roles from reactions.我正在尝试制作一个不和谐的机器人,从反应中添加角色。 I've been following a tutorial from CodeLyon and I hit a snag and I cant find a fix我一直在学习 CodeLyon 的教程,但遇到了障碍,找不到修复方法
Basically, I got the bot to send a embed message and it adds the reactions to the message.基本上,我让机器人发送一条嵌入的消息,并将反应添加到消息中。 But it doesn't add the roles.但它没有添加角色。
module.exports = {
name: "reactionrole",
description: "Sets up a reaction role message!",
async execute(message, args, Discord, client) {
const channel = "907732565685846036";
const ACRole = message.guild.roles.cache.find(
(role) => role.name === "Animal Crossing"
);
const ACEmoji = "🐸";
let embed = new Discord.MessageEmbed()
.setColor("#e42643")
.setTitle("Choose which games you play!")
.setDescription(
"React to add the games you play as a role (and receive pings)\n\n" +
`${ACEmoji} for Animal Crossing\n`
);
let messageEmbed = await message.channel.send({ embeds: [embed] });
messageEmbed.react(ACEmoji);
client.on("messageReactionAdd", async (reaction, user) => {
if (reaction.message.partial) await reaction.message.fetch();
if (reaction.partial) await reaction.fetch();
if (user.bot) return;
if (!reaction.message.guild) return;
if (reaction.message.channel.id == channel) {
if (reaction.emoji.name === ACEmoji) {
await reaction.message.guild.members.cache
.get(user.id)
.roles.add(ACRole);
}
} else {
return;
}
});
client.on("messageReactionRemove", async (reaction, user) => {
if (reaction.message.partial) await reaction.message.fetch();
if (reaction.partial) await reaction.fetch();
if (user.bot) return;
if (!reaction.message.guild) return;
if (reaction.message.channel.id == channel) {
if (reaction.emoji.name === ACEmoji) {
await reaction.message.guild.members.cache
.get(user.id)
.roles.remove(ACRole);
}
} else {
return;
}
});
},
};
In my main.js (some people use index.js) file I had to change const client = new Discord.Client({ intents: ['GUILDS', 'GUILD_MESSAGES', 'GUILD_MESSAGE'] }, { partials: ["MESSAGE", "CHANNEL", "REACTION" ] })
在我的 main.js(有些人使用 index.js)文件中,我不得不更改const client = new Discord.Client({ intents: ['GUILDS', 'GUILD_MESSAGES', 'GUILD_MESSAGE'] }, { partials: ["MESSAGE", "CHANNEL", "REACTION" ] })
to到
const client = new Discord.Client({ intents: ['GUILDS', 'GUILD_MESSAGES', 'GUILD_MESSAGE_REACTIONS'] }, { partials: ["MESSAGE", "CHANNEL", "REACTION" ] })
It fixed it for a little bit but it randomly stopped working again.它修复了一点,但它又随机停止工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.