Throw error if no permissions to post in log channel

If the bot has no permission to send messages to the log channel, we throw an error in DMs
This commit is contained in:
xBelladonna 2019-06-15 12:41:13 +09:30 committed by Bella | Nightshade
parent 6eae3c02fa
commit d8589ca9ae

View file

@ -17,5 +17,23 @@ async def set_log(ctx: CommandContext):
raise CommandError("Channel not found.")
channel_id = channel.id
await db.update_server(ctx.conn, server.id, logging_channel_id=channel_id)
await ctx.reply_ok("Updated logging channel." if channel_id else "Cleared logging channel.")
# Check if we can send messages in the log channel. If not, raise an error
# in the channel. If we don't have permission to do that, DM the user who sent
# the command and skip updating the log channel in the database
try:
# Send a message in the log channel to confirm and also to test permission.
if channel_id:
await channel.send("✅ PluralKit will now log proxied messages in this channel.")
await db.update_server(ctx.conn, server.id, logging_channel_id=channel_id)
await ctx.reply_ok("Updated logging channel." if channel_id else "Cleared logging channel.")
except discord.Forbidden:
# Try (heh) to let the user know we don't have permission to post there
error_msg = "PluralKit doesn't have permission to read and/or send messages in that channel! Please check my permissions then try again."
raise CommandError(error_msg)
# nested try asdhfakjd
try:
# Failing that, we DM the user who issued the command
await ctx.message.author.send(await CommandError(error_msg))
except discord.Forbidden:
# and if that fails, well... crap, nothing we can do
pass