Don't attempt to send log messages if the bot doesn't have permissions

This commit is contained in:
Ske
2020-02-22 01:54:10 +01:00
parent 493f7b12e5
commit 8d3be79d33
4 changed files with 15 additions and 11 deletions

View File

@@ -33,9 +33,14 @@ namespace PluralKit.Bot {
// Bail if we can't find the channel
if (!(await _client.GetChannelAsync(guildCfg.Value.LogChannel.Value) is ITextChannel logChannel)) return;
// Bail if we don't have permission to send stuff here
if (!logChannel.HasPermission(ChannelPermission.SendMessages) || !logChannel.HasPermission(ChannelPermission.EmbedLinks))
return;
var embed = _embed.CreateLoggedMessageEmbed(system, member, messageId, originalMsgId, sender, content, originalChannel);
var url = $"https://discordapp.com/channels/{originalChannel.GuildId}/{originalChannel.Id}/{messageId}";
await logChannel.SendMessageAsync(text: url, embed: embed);
}
}

View File

@@ -286,7 +286,7 @@ namespace PluralKit.Bot
// Finally remove the original reaction (if we can)
var user = await _client.Rest.GetUserAsync(userWhoReacted);
if (user != null && await realMessage.Channel.HasPermission(ChannelPermission.ManageMessages))
if (user != null && realMessage.Channel.HasPermission(ChannelPermission.ManageMessages))
await realMessage.RemoveReactionAsync(reactedEmote, user);
}
@@ -316,7 +316,7 @@ namespace PluralKit.Bot
// And finally remove the original reaction (if we can)
var msgObj = await message.GetOrDownloadAsync();
if (await msgObj.Channel.HasPermission(ChannelPermission.ManageMessages))
if (msgObj.Channel.HasPermission(ChannelPermission.ManageMessages))
await msgObj.RemoveReactionAsync(reactedEmote, user);
}