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

查看:15
本文介绍了使用表情来赋予角色 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!

参考资料:

公会成员, 消息反应事件, 用户对象

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

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