Handle send message/embed links permission erorrs gracefully

This commit is contained in:
Ske
2020-02-24 09:57:16 +01:00
parent 9d4993b121
commit a95d12639d
3 changed files with 26 additions and 8 deletions

View File

@@ -53,8 +53,17 @@ namespace PluralKit.Bot
public bool HasNext(bool skipFlags = true) => RemainderOrNull(skipFlags) != null;
public string FullCommand => _parameters.FullCommand;
public Task<IUserMessage> Reply(string text = null, Embed embed = null) =>
Channel.SendMessageAsync(text, embed: embed);
public Task<IUserMessage> Reply(string text = null, Embed embed = null)
{
if (!this.BotHasPermission(ChannelPermission.SendMessages))
// Will be "swallowed" during the error handler anyway, this message is never shown.
throw new PKError("PluralKit does not have permission to send messages in this channel.");
if (embed != null && !this.BotHasPermission(ChannelPermission.EmbedLinks))
throw new PKError("PluralKit does not have permission to send embeds in this channel. Please ensure I have the **Embed Links** permission enabled.");
return Channel.SendMessageAsync(text, embed: embed);
}
/// <summary>
/// Checks if the next parameter is equal to one of the given keywords. Case-insensitive.