#Get user's color
1 messages · Page 1 of 1 (latest)
This should work just fine:
[Command("test")]
public async Task GrabbingUserRoleColor(SocketGuildUser user){
// grabs the highest role and the color for it
var userHighestRoleColor = user.Roles.OrderBy(r => r.Position).Last().Color;
//returns the hex code for it
await ReplyAsync($"This user's color is {userHighestRoleColor}");
}
sometimes the highest role isn't necessarily the color determinant role
just write a conditional statement that if the highest role color is == Default then create a new IEnumerable that filters a sequence of values based on a predicate
Here you are:
[Command("test")]
public async Task GrabbingUserRoleColor(SocketGuildUser user){
// filters out any roles that are default color
var filterOutDefault = user.Roles.Where(r => r.Color != Color.Default);
// grabs the highest role and the color for it
var userHighestRoleColor = filterOutDefault.OrderBy(r => r.Position).Last().Color;
// returns the hex code for it
await ReplyAsync($"This user's color is {userHighestRoleColor}");
}
no conditional needed, i just filtered out the roles that are default color