diff options
| author | 2020-03-04 17:18:35 +1000 | |
|---|---|---|
| committer | 2020-03-04 17:18:35 +1000 | |
| commit | 1cd6cf6ebef0bf82fb6c917a5a97bba294879ab0 (patch) | |
| tree | d276784370b5712aa72cce3be71d903a889aa2dd | |
| parent | Merge pull request #750 from python-discord/bug/backend/b748/resolver-in-coro (diff) | |
| parent | Prevent exception if a watched user sends a DM to the bot (diff) | |
Merge pull request #815 from python-discord/watchchannel-dm
Prevent exception if a watched user sends a DM to the bot
| -rw-r--r-- | bot/cogs/watchchannels/watchchannel.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/bot/cogs/watchchannels/watchchannel.py b/bot/cogs/watchchannels/watchchannel.py index 3667a80e8..479820444 100644 --- a/bot/cogs/watchchannels/watchchannel.py +++ b/bot/cogs/watchchannels/watchchannel.py @@ -9,7 +9,7 @@ from typing import Optional import dateutil.parser import discord -from discord import Color, Embed, HTTPException, Message, errors +from discord import Color, DMChannel, Embed, HTTPException, Message, errors from discord.ext.commands import Cog, Context from bot.api import ResponseCodeError @@ -273,7 +273,14 @@ class WatchChannel(metaclass=CogABCMeta): reason = self.watched_users[user_id]['reason'] - embed = Embed(description=f"{msg.author.mention} in [#{msg.channel.name}]({msg.jump_url})") + if isinstance(msg.channel, DMChannel): + # If a watched user DMs the bot there won't be a channel name or jump URL + # This could technically include a GroupChannel but bot's can't be in those + message_jump = "via DM" + else: + message_jump = f"in [#{msg.channel.name}]({msg.jump_url})" + + embed = Embed(description=f"{msg.author.mention} {message_jump}") embed.set_footer(text=f"Added {time_delta} by {actor} | Reason: {reason}") await self.webhook_send(embed=embed, username=msg.author.display_name, avatar_url=msg.author.avatar_url) |