我的反应角色机器人编写了嵌入消息,但反应没有添加角色
Posted
技术标签:
【中文标题】我的反应角色机器人编写了嵌入消息,但反应没有添加角色【英文标题】:My reaction role bot write the embed message but the reaction doesn't add role 【发布时间】:2021-11-13 20:11:22 【问题描述】:我的反应角色机器人发送带有反应的嵌入消息,但是当您选择反应时,角色不是属性
我有这个代码 index.js:
const Discord = require("discord.js");
const client = new Discord.Client( intents: ["GUILDS", "GUILD_MESSAGES"], partials: ["MESSAGE", "CHANNEL", "REACTION", "MANAGE_ROLES"] )
require("dotenv").config();
const prefix = "!";
const fs = require("fs");
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync("./commands/").filter(file => file.endsWith('.js'));
for (const file of commandFiles)
const command = require(`./commands/$file`);
client.commands.set(command.name, command);
client.on("ready", () =>
console.log("bot online");
);
client.on("messageCreate", message =>
if(!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if (command === "reactionrole")
client.commands.get("reactionrole").execute(message, args, Discord, client);
);
client.login(process.env.BOT_TOKEN);
reactionrole.js:
module.exports =
name: 'reactionrole',
description: "Sets up a reaction role message",
async execute(message, args, Discord, client)
const channel = "889233386781151232";
const maths = message.guild.roles.cache.find(role => role.name === "Maths");
const mathsExpertes = message.guild.roles.cache.find(role => role.name === "Maths expertes");
const nsi = message.guild.roles.cache.find(role => role.name === "NSI");
const physique = message.guild.roles.cache.find(role => role.name === "Physique");
const svt = message.guild.roles.cache.find(role => role.name === "SVT");
const artsPlastique = message.guild.roles.cache.find(role => role.name === "Arts Plastiques");
const mathsEmoji = '????';
const mathsExpertesEmoji = '????';
const nsiEmoji = '????';
const physiqueEmoji = '????';
const svtEmoji = '????';
const artsPlastiquesEmoji = '????';
let embed = new Discord.MessageEmbed()
.setColor("#e42643")
.setTitle("Selection des matière")
.setDescription("Choisis tes matières en cliquant sur la reaction qui correspond\n\n"
+ `$mathsEmoji : Maths\n`
+ `$mathsExpertesEmoji : Maths Expertes\n`
+ `$nsiEmoji : NSI\n`
+ `$physiqueEmoji : Physique\n`
+ `$svtEmoji : SVT\n`
+ `$artsPlastiquesEmoji : Arts Plastiques\n`);
let messageEmbed = await message.channel.send(embeds: [embed]);
messageEmbed.react(mathsEmoji);
messageEmbed.react(mathsExpertesEmoji);
messageEmbed.react(nsiEmoji);
messageEmbed.react(physiqueEmoji);
messageEmbed.react(svtEmoji);
messageEmbed.react(artsPlastiquesEmoji);
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 === mathsEmoji)
await reaction.message.guild.members.cache.get(user.id).roles.add(maths);
if (reaction.emoji.name === mathsExpertesEmoji)
await reaction.message.guild.members.cache.get(user.id).roles.add(mathsExpertes);
if (reaction.emoji.name === nsiEmoji)
await reaction.message.guild.members.cache.get(user.id).roles.add(nsi);
if (reaction.emoji.name === physiqueEmoji)
await reaction.message.guild.members.cache.get(user.id).roles.add(physique);
if (reaction.emoji.name === svtEmoji)
await reaction.message.guild.members.cache.get(user.id).roles.add(svt);
if (reaction.emoji.name === artsPlastiquesEmoji)
await reaction.message.guild.members.cache.get(user.id).roles.add(artsPlastique);
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 === mathsEmoji)
await reaction.message.guild.members.cache.get(user.id).roles.remove(maths);
if (reaction.emoji.name === mathsExpertesEmoji)
await reaction.message.guild.members.cache.get(user.id).roles.remove(mathsExpertes);
if (reaction.emoji.name === nsiEmoji)
await reaction.message.guild.members.cache.get(user.id).roles.remove(nsi);
if (reaction.emoji.name === physiqueEmoji)
await reaction.message.guild.members.cache.get(user.id).roles.remove(physique);
if (reaction.emoji.name === svtEmoji)
await reaction.message.guild.members.cache.get(user.id).roles.remove(svt);
if (reaction.emoji.name === artsPlastiquesEmoji)
await reaction.message.guild.members.cache.get(user.id).roles.remove(artsPlastique);
else
return;
);
在启动命令时,我有这个显示为错误
(node:8760) DeprecationWarning:消息事件已被弃用。改用 messageCreate
(使用node --trace-deprecation ...
显示警告的创建位置)
你能帮帮我吗
我知道已经有人问过这个问题,但我不明白答案或不清楚
【问题讨论】:
【参考方案1】:这很不言自明。您在代码中的某个地方使用了这个:
client.on('message', message =>
// Some code
);
但由于 Discord.js v13 你必须使用messageCreate
而不是message
:
client.on('messageCreate', message =>
// Some code
);
【讨论】:
我不知道在哪里放置 messageCreate ! 但现在我知道了 这不起作用我试过了,但它不起作用我没有错误消息但没有分配角色以上是关于我的反应角色机器人编写了嵌入消息,但反应没有添加角色的主要内容,如果未能解决你的问题,请参考以下文章
Discord JS //尝试通过响应消息来添加角色和删除角色
当有人对消息做出反应时,我如何让我的 discord.js 机器人添加角色?