mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-17 03:00:13 +00:00
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:
parent
6eae3c02fa
commit
d8589ca9ae
1 changed files with 20 additions and 2 deletions
|
|
@ -17,5 +17,23 @@ async def set_log(ctx: CommandContext):
|
||||||
raise CommandError("Channel not found.")
|
raise CommandError("Channel not found.")
|
||||||
channel_id = channel.id
|
channel_id = channel.id
|
||||||
|
|
||||||
await db.update_server(ctx.conn, server.id, logging_channel_id=channel_id)
|
# Check if we can send messages in the log channel. If not, raise an error
|
||||||
await ctx.reply_ok("Updated logging channel." if channel_id else "Cleared logging channel.")
|
# 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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue