0

I'm using Visual Studio and Discord.Net v2.1.1.

I've searched all over, but nothing I've found shows me a way to be able to modify a role's colour (or IRole).

Is there any other way to do this? What am I doing wrong?

Context.Guild.GetRole(roleid).ModifyAsync(???);

edit: this worked for me: await Context.Guild.GetRole(roleid).ModifyAsync(x => x.Color = new Color(1, 4, 150));

  • https://github.com/discord-net/Discord.Net/blob/release/1.0.2/src/Discord.Net.Core/Entities/Roles/RoleProperties.cs#L4 – stuartd Jul 17 '19 at 01:03
  • 1
    For future reference, this is actually documented in the respective `XProperties` documentation, in this case, [RoleProperties](https://docs.stillu.cc/api/Discord.RoleProperties.html) – Still Jul 17 '19 at 06:19

1 Answers1

2

Short Answer

In Discord.Net, most if not all ModifyAsync takes an Action<T> as its parameter, and its documentation and such usage is in its respective XProperties documentation. In this case, RoleProperties.

enter image description here

Long Answer

Since these methods all take an Action<T>, we can take a look at what Action is on Microsoft .NET API Documentation. From the documentation, we learn that it is a delegate, and the easiest way to make a delegate is with a lambda expression (also see Func vs. Action vs. Predicate).

From this, we can come up the following,

var role = guild.GetRole(id);
await role.ModifyAsync(role =>
{
    // Assign the color to a new Discord.Color struct of color [123, 123, 123]
    role.Color = new Color(123, 123, 123);
});

All ModifyAsyncs work more or less the same.

Still
  • 322
  • 3
  • 12