使用表情赋予角色Discord.js [英] Using emotes to give roles Discord.js

查看:35
本文介绍了使用表情赋予角色Discord.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的不和谐服务器中,作为一种验证方法,我希望我的机器人让所有用户对消息做出反应,然后获得已验证的角色,并删除旧的角色.我拥有的当前代码不会授予或删除角色,但不会出错.

In my discord server, as a verification method, I want my bot to have all users react to the message and then get given the verified role, and remove the old role. The current code I have doesn't grant or remove roles, but doesn't error.

client.on("messageReactionAdd", function(users) {
users.addRole(users.guild.roles.find("name", setup.verify));
users.removeRole(users.guild.roles.find("name", setup.default));
});

推荐答案

当前代码有问题. messageReactionAdd 事件返回一个 User 对象,该对象不包含您尝试访问的属性 .guilds : users.guilds.r-.

There is a problem in the current code. The messageReactionAdd event returns a User object, which does not contain the property .guilds which you attempt to access: users.guilds.r- .

也许应该代替 User 对象的 id 并将其插入 message.guild.members.get("id here").然后将返回的 Member 对象与当前代码一起使用.应该可以!

Instead of this perhaps you should the id of the User object and plug that into message.guild.members.get("id here"). Then use the returned Member object with your current code. That should work!

参考文献:

公会成员消息响应事件,<一个href ="https://discord.js.org/#/docs/main/stable/class/User" rel ="nofollow noreferrer">用户对象

这篇关于使用表情赋予角色Discord.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆