fix error message on invalid guild ID

This commit is contained in:
spiral 2021-04-19 21:38:03 +01:00
parent a2d2036851
commit 85615b3f68
No known key found for this signature in database
GPG Key ID: A6059F0CA0E1BD31
2 changed files with 7 additions and 2 deletions

View File

@ -126,7 +126,12 @@ namespace PluralKit.Bot {
if (!ulong.TryParse(guildIdStr, out var guildId)) if (!ulong.TryParse(guildIdStr, out var guildId))
throw new PKSyntaxError($"Could not parse {guildIdStr.AsCode()} as an ID."); throw new PKSyntaxError($"Could not parse {guildIdStr.AsCode()} as an ID.");
guild = await _rest.GetGuild(guildId); try {
guild = await _rest.GetGuild(guildId);
} catch (Myriad.Rest.Exceptions.ForbiddenException) {
throw Errors.GuildNotFound(guildId);
}
if (guild != null) if (guild != null)
senderGuildUser = await _rest.GetGuildMember(guildId, ctx.Author.Id); senderGuildUser = await _rest.GetGuildMember(guildId, ctx.Author.Id);
if (guild == null || senderGuildUser == null) if (guild == null || senderGuildUser == null)

View File

@ -98,7 +98,7 @@ namespace PluralKit.Bot {
public static PKError DurationParseError(string durationStr) => new PKError($"Could not parse {durationStr.AsCode()} as a valid duration. Try a format such as `30d`, `1d3h` or `20m30s`."); public static PKError DurationParseError(string durationStr) => new PKError($"Could not parse {durationStr.AsCode()} as a valid duration. Try a format such as `30d`, `1d3h` or `20m30s`.");
public static PKError FrontPercentTimeInFuture => new PKError("Cannot get the front percent between now and a time in the future."); public static PKError FrontPercentTimeInFuture => new PKError("Cannot get the front percent between now and a time in the future.");
public static PKError GuildNotFound(ulong guildId) => new PKError($"Guild with ID {guildId} not found. Note that you must be a member of the guild you are querying."); public static PKError GuildNotFound(ulong guildId) => new PKError($"Guild with ID `{guildId}` not found, or I cannot access it. Note that you must be a member of the guild you are querying.");
public static PKError DisplayNameTooLong(string displayName, int maxLength) => new PKError( public static PKError DisplayNameTooLong(string displayName, int maxLength) => new PKError(
$"Display name too long ({displayName.Length} > {maxLength} characters). Use a shorter display name, or shorten your system tag."); $"Display name too long ({displayName.Length} > {maxLength} characters). Use a shorter display name, or shorten your system tag.");