Discord 向对bot消息问题作出反应的用户添加角色

Discord 向对bot消息问题作出反应的用户添加角色,discord,discord.js,Discord,Discord.js,我有一个命令,机器人用一条消息响应,并向其添加一个反应,如果键入命令的人对其作出反应,他们将获得角色,但我希望任何人都能够对其作出反应,因为我只想键入一次。它可以工作,但只适用于键入命令的人 我尝试过使用其他的解决方案,但其他的似乎都不起作用 client.on("message", (message) => { client.on('messageReactionAdd', (reaction, user) => { if(reaction.emoji.n

我有一个命令,机器人用一条消息响应,并向其添加一个反应,如果键入命令的人对其作出反应,他们将获得角色,但我希望任何人都能够对其作出反应,因为我只想键入一次。它可以工作,但只适用于键入命令的人

我尝试过使用其他的解决方案,但其他的似乎都不起作用

client.on("message", (message) => {

    client.on('messageReactionAdd', (reaction, user) => {
        if(reaction.emoji.name === "The 
messageReactionAdd
event has two parameters -
MessageReaction
and
User
.
In your example, those would be
reaction
and
user
. You are utilizing the
reaction
parameter to ensure that the reaction added in in fact the one you want. However, when it comes to adding the role to the person that added the reaction, you are referencing
member
which is actually the person that sent the message (
message.member
), not the person that added the reaction to the message.

To add the role to anyone that reacts, you'd need to
Change:

member.addRole(role)

To either an async event with: (
client.on('messageReactionAdd', async (reaction, user) =>
)

const guildmember = await guild.fetchMember(user);
guildmember.addRole(role);
client.on(“message”,(message)=>{
client.on('messageReactionAdd',(reaction,user)=>{

如果(reaction.emoji.name==”则
messageReactionAdd
事件有两个参数-
MessageReaction
User

在您的示例中,这些将是
反应
用户
。您正在使用
反应
参数来确保添加的反应实际上是您想要的反应。但是,当涉及到向添加反应的人员添加角色时,您引用的是
成员
,而实际上是添加反应的人员发送消息(
message.member
),而不是向消息添加反应的人

要将角色添加到任何有反应的人,您需要
更改:

member.addRole(角色)

与以下内容之一的异步事件(
client.on('messageReactionAdd',async(reaction,user)=>

或者:


编辑:
addRole
函数只存在于
guildMember
对象上,因为您只能向公会中的某个人添加角色。

这给了我“user.addRole不是函数”啊,您的用户需要是公会成员尝试执行
var guildMember=guild.fetchMember(user);
client.on('messageReactionAdd',(reaction,user)=>{if(reaction.emoji.name==”这肯定是因为我对这篇文章进行了编辑,你错过了
fetchMember
async
并且需要一个
。然后
等待
你不应该这样做。查找reaction collector。这将完全满足你的需要,而不必添加很多事件
guild.fetchMember(user).then(guildmember => guildmember.addRole(role));