diff options
| author | 2022-02-14 10:27:34 +0000 | |
|---|---|---|
| committer | 2022-02-14 10:27:34 +0000 | |
| commit | b651e3498fa49de527a0c8d4d5a441a30f85c88b (patch) | |
| tree | 6f10851f8c38c0c400afd498f852f577bc128892 | |
| parent | Removed extra newline in the traceback tag. (#2083) (diff) | |
Fix DM handling for code snippets.
| -rw-r--r-- | bot/exts/info/code_snippets.py | 27 | 
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),  |