简体   繁体   English

在用户单击消息上的反应时向用户添加角色

[英]Adding a role to a user when they click a reaction on a message

I am setting up a new entry system for my Discord server with my bot, but I am having a hang up on getting some code to function.我正在用我的机器人为我的 Discord 服务器设置一个新的入口系统,但我在让一些代码运行时遇到了问题。

My basic goal, is to have a post sitting in the welcome channel with rules and info, and the user has to click a reaction on the post, then the bot gives them a specific role and removes the 'Newbie' role.我的基本目标是在欢迎频道中发布一个包含规则和信息的帖子,用户必须点击帖子上的反应,然后机器人给他们一个特定的角色并删除“新手”角色。 I have no had any issues doing this as long as the user is the one calling the message, but my issue comes in when trying to pull the guildMember object in, so I can roles.add them, it just doesn't seem to work?只要用户是调用消息的人,我就不会遇到任何问题,但是在尝试拉入 guildMember 对象时出现了我的问题,因此我可以使用角色。添加它们,它似乎不起作用? I've tried several different methods and have came up short every time.我尝试了几种不同的方法,但每次都失败了。 :C :C

message_id is being identified and ran properly, I am console logging and caching it outside of this block, seems fine. message_id 正在被识别并正常运行,我正在控制台日志记录并将其缓存在此块之外,似乎没问题。 It's just this part that I cannot get to work.只是这部分我无法开始工作。 The bot doesn't error, or reply to the event.机器人不会出错,也不会回复事件。

Using node.js 12 (dino is my Client, btw)使用 node.js 12(dino 是我的客户端,顺便说一句)

    dino.on("messageReactionAdd", (reaction, user) => {
    if (reaction.emoji.id == '☑️' && reaction.message.id === message_id) {
        let ourUser = reaction.message.guild.member(user)
        ourUser.roles.add(`add ID would go here`)
        ourUser.roles.remove(`Remove ID would go here`)
    }
});

I found the issue, I was calling emoji.id instead of emoji.name lol.我发现了这个问题,我正在调用 emoji.id 而不是 emoji.name 哈哈。 I'm an idiot.我是个白痴。 Works fine now, soon as I post it, I figure it out.. ofc.现在工作正常,我一发布,我就弄清楚了.. ofc。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM