fix: correctly handle missing role cache in message embed
This commit is contained in:
parent
08c5b78cc2
commit
21e3e61db0
@ -40,7 +40,7 @@ namespace Myriad.Extensions
|
||||
public static Role GetRole(this IDiscordCache cache, ulong roleId)
|
||||
{
|
||||
if (!cache.TryGetRole(roleId, out var role))
|
||||
throw new KeyNotFoundException($"User {roleId} not found in cache");
|
||||
throw new KeyNotFoundException($"Role {roleId} not found in cache");
|
||||
return role;
|
||||
}
|
||||
|
||||
|
@ -331,9 +331,16 @@ namespace PluralKit.Bot
|
||||
var roles = memberInfo?.Roles?.ToList();
|
||||
if (roles != null && roles.Count > 0)
|
||||
{
|
||||
// TODO: what if role isn't in cache? figure out a fallback
|
||||
var rolesString = string.Join(", ", roles
|
||||
.Select(id => _cache.GetRole(id))
|
||||
.Select(id => {
|
||||
_cache.TryGetRole(id, out var role);
|
||||
if (role != null)
|
||||
return role;
|
||||
return new Role() {
|
||||
Name = "*(unknown role)*",
|
||||
Position = 0,
|
||||
};
|
||||
})
|
||||
.OrderByDescending(role => role.Position)
|
||||
.Select(role => role.Name));
|
||||
eb.Field(new($"Account roles ({roles.Count})", rolesString.Truncate(1024)));
|
||||
|
Loading…
Reference in New Issue
Block a user