Using emotes to give roles Discord.js

女生的网名这么多〃 提交于 2021-01-28 01:09:51

问题


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));
});

回答1:


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- .

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!

References:

Guild Member , Message Reaction Event, User Object




回答2:


Would something like this work? I'm not sure it will I haven't tested it. This should add the role if the message they reacted to consists of the word "role1" and if they react to a different message it will remove the role. I don't know if this is what you're going for but in theory this should work.

 client.on("MessageReactionAdd", function(users) {
if (message.content === "role1") {
  users.addRole(users.guild.roles.find("name", setup.verify))
} else if (!message.content === "role1") {
  user.removeRole(users.guild.role.find("name", setup.default))
}
});



回答3:


Are the names of the roles; setup.verify & setup.default?
If not, that's why it is not working.

Try:

client.on("messageReactionAdd", function(users) {
users.addRole(users.guild.roles.find("id", ROLEIDHERE));
users.removeRole(users.guild.roles.find("id", ROLEIDHERE));
});

where ROLEIDHERE put the role id to find the role id just tag the role and before you hit send put \ before the tag and it will supply the id



来源:https://stackoverflow.com/questions/48033935/using-emotes-to-give-roles-discord-js

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!