question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Roles of the member is not updated

See original GitHub issue

Since some functions of 3.x do not work at some point, I am migrating my project to version 4. But I still have problems. When I use GrantRoleAsync or RevokeRoleAsync of DiscordMember, It is not reflected to Roles.

I use .Net Core 2.1 and D#+ 4.0.0-nightly-00745.

Here is the code.

(First step):

var guild = discord.GetGuildAsync(DiscordConstants.GuildId).Result;
var member = guild.GetMemberAsync(id).Result;
var fooRole = guild.GetRole(DiscordConstants.FooRoleId);
var barRole = guild.GetRole(DiscordConstants.BarRoleId);

// In this example, it is assumed that the user has the Foo role.
if (member.Roles.Count() > 0 && member.Roles.Any(role => role.Name == "Foo"))
{
    // Grant Bar, Revoke Foo.
    member.GrantRoleAsync(barRole, reason).Wait();
    member.RevokeRoleAsync(fooRole, reason).Wait();
}

(In other method that called in few seconds later):

var guild = discord.GetGuildAsync(DiscordConstants.GuildId).Result;
var member = guild.GetMemberAsync(id).Result;
var fooRole = guild.GetRole(DiscordConstants.FooRoleId);
var barRole = guild.GetRole(DiscordConstants.BarRoleId);

// This condition is not satisfied.
// `Roles` still has "Foo" and doesn't have "Bar".
if (member.Roles.Count() > 0 && member.Roles.Any(role => role.Name == "Bar"))
{
    // Grant Foo, Revoke Bar. (Never executed.)
    member.GrantRoleAsync(fooRole, reason).Wait();
    member.RevokeRoleAsync(barRole, reason).Wait();
}

Need help.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
NeuroWhAIcommented, Oct 31, 2020

Solved by turning on the bot’s intent setting which is SERVER MEMBERS INTENT in the developer portal. Thank you all.

0reactions
Neuheitcommented, Oct 30, 2020

I know this is not good code. But is that related to my problem? I just make it works.

I would fix what I mentioned above first. If you’re still having issues with that it is likely due to intents.

Read more comments on GitHub >

github_iconTop Results From Across the Web

"Unable to Update Role" When trying to change role name ...
When I went to update one of my group members' roles, it simply prompted me saying “Unable to update the user's role.”. I...
Read more >
Roles not updating
I can update the roles I created on WordPress's own roles and with this plugin. But, This plugin does not update the permissions...
Read more >
role does not meet the selected updated criteria".
Hi,. I am now able to update the mass roles with role owner. However, strange thing is that while updating role owner, I...
Read more >
Discord.py not seeing updates to User/Member roles
Restarting the bot allows one update again before it breaks, so it makes me think that something isn't updating when the user's roles...
Read more >
Discord roles not updating
I'm trying to implement a way for my players Discord roles to be updated when they purchase a VIP and their Oxide group...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found