bot.on('messageReactionAdd', async (reaction, user) => {
// Define the emoji user add
let role = message.guild.roles.find(role => role.name === 'Alerts');
if (message.channel.name !== 'alerts') return message.reply(':x: You must go to the channel #alerts');
message.member.addRole(role);
});
这是我的 bot.js 的一部分。我希望用户在某个 channel 中使用react并接收 Angular 色警报
最佳答案
你还没有真正说明问题是什么,什么有效,什么无效,但我会在一些引起我注意的部分进行疯狂的尝试。
对于初学者,您正在调用变量 message
的属性而在您提供的代码中,您没有创建/设置名为 message
的变量。我的猜测是您想要已添加 react 的消息。为此,您必须使用 MessageReaction
messageReactionAdd
中提供的参数事件为reaction
.
从那里您可以替换 message.<something>
与 reaction.message.<something>
您提供的代码中的任何地方。
还需要注意的是,您将 Angular 色警报添加到 message.member
。这不会按您希望的方式工作,因为它会将警报 Angular 色授予原始消息的作者。
(我认为)您想要做的是获取刚刚对表情符号使用react的用户,并为他们分配警报 Angular 色。您必须先找到公会中的成员,然后为他们分配警报 Angular 色。为此,您必须使用 User
参数并找到正确的 Member
因为您无法将 Angular 色添加到用户对象,但可以添加到成员对象。下面是一些代码,希望能让您走上正轨。
// Fetch and store the guild (the server) in which the message was send.
const guild = reaction.message.guild;
const memberWhoReacted = guild.members.find(member => member.id === user.id);
memberWhoReacted.addRole(role);
关于javascript - Discord JS//尝试通过对消息使用react来添加角色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59069737/