Retrieving & adding roles with getRole vs. fetch()
#11233
-
Which application is this bug report for?Documentation Issue descriptionThere's a bit of a discrepancy between the FAQ guides and the documentation and would love some clarification. I'm just confused as to where these get methods are being defined for roles, as the docs use fetch requests instead. I see that To be more specific, the way I added roles based off of a message reaction: // inside of Events.MessageReactionAdd
const guild = reaction.message.guild;
await guild.members.fetch(user.id).then((m) => {
m.guild.roles.fetch("1433556412964802660").then((r) => {
m.roles.add(r);
});
});But based off the FAQ, adding roles is done through const role = interaction.options.getRole('role');
const member = interaction.options.getMember('target');
member.roles.add(role);Steps to Reproduce
const role = interaction.options.getRole('role');
// Fetch a single role
message.guild.roles.fetch('222078108977594368')
.then(role => console.log(`The role color is: ${role.colors.primaryColor}`))
.catch(console.error);Versions
Issue priorityLow (slightly annoying) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
|
the guild member instance (retrieved via if you have the id, you can simply pass the id here and don't need to fetch the role. to clarify, there is no discrepancy here, just a different entry point. you still use the exact same approach, no matter where you got the guild member instance from - |
Beta Was this translation helpful? Give feedback.
getMember/getRoleare convenience functions we define for interactions that let you retrieve the command options the user supplied (that being a member and a role in this example).the guild member instance (retrieved via
getMemberor from the cache/rest call with.members.fetch("id")) then has the.roles.add()function on the guild member roles manager, to actually add a role.if you have the id, you can simply pass the id here and don't need to fetch the role.
if you don't want to, you don't even have to fetch the member and can utilize the manager instead:
<Guild>.members.addRole({role: "id", user: user.id})to clarify, there is no discrepancy here, just a different entry point. yo…