aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bot/exts/info/code_snippets.py27
1 files changed, 17 insertions, 10 deletions
diff --git a/bot/exts/info/code_snippets.py b/bot/exts/info/code_snippets.py
index 07b1b8a2d..95a0fb014 100644
--- a/bot/exts/info/code_snippets.py
+++ b/bot/exts/info/code_snippets.py
@@ -255,16 +255,23 @@ class CodeSnippets(Cog):
except discord.NotFound:
# Don't send snippets if the original message was deleted.
return
-
- if len(message_to_send) > 1000 and message.channel.id != Channels.bot_commands:
- # Redirects to #bot-commands if the snippet contents are too long
- await self.bot.wait_until_guild_available()
- destination = self.bot.get_channel(Channels.bot_commands)
-
- await message.channel.send(
- 'The snippet you tried to send was too long. '
- f'Please see {destination.mention} for the full snippet.'
- )
+ except discord.Forbidden as e:
+ # We still want to send snippets when in DMs, but if we're in guild then
+ # reraise error since that means there's a permissions issue with the bot.
+ if message.guild:
+ raise e
+
+ # If we're in a guild, then check if we need to redirect to #bot-commands
+ if destination.guild:
+ if len(message_to_send) > 1000 and message.channel.id != Channels.bot_commands:
+ # Redirects to #bot-commands if the snippet contents are too long
+ await self.bot.wait_until_guild_available()
+ destination = self.bot.get_channel(Channels.bot_commands)
+
+ await message.channel.send(
+ 'The snippet you tried to send was too long. '
+ f'Please see {destination.mention} for the full snippet.'
+ )
await wait_for_deletion(
await destination.send(message_to_send),