From d8589ca9ae05bfdcb80940326068844ab73859a2 Mon Sep 17 00:00:00 2001 From: xBelladonna Date: Sat, 15 Jun 2019 12:41:13 +0930 Subject: [PATCH] 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 --- src/pluralkit/bot/commands/mod_commands.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/pluralkit/bot/commands/mod_commands.py b/src/pluralkit/bot/commands/mod_commands.py index 47c05fcc..1a109beb 100644 --- a/src/pluralkit/bot/commands/mod_commands.py +++ b/src/pluralkit/bot/commands/mod_commands.py @@ -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 \ No newline at end of file