From efcf91e934b9cadee52c99a6005c5ba3bbae66e5 Mon Sep 17 00:00:00 2001 From: Flame442 <34169552+Flame442@users.noreply.github.com> Date: Thu, 29 Aug 2019 21:19:19 -0400 Subject: [PATCH] Catch discord.errors.Forbidden when DMing a user the invite message (#2948) * Catch discord.errors.Forbidden when DMing a user the invite message Uses the same error message as `[p]help` * Create 2948.bugfix.rst * You saw nothing --- changelog.d/2948.bugfix.rst | 1 + redbot/core/core_commands.py | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 changelog.d/2948.bugfix.rst diff --git a/changelog.d/2948.bugfix.rst b/changelog.d/2948.bugfix.rst new file mode 100644 index 000000000..aeee92878 --- /dev/null +++ b/changelog.d/2948.bugfix.rst @@ -0,0 +1 @@ +The [p]invite command no longer errors when a user has the bot blocked or DMs disabled in the server. diff --git a/redbot/core/core_commands.py b/redbot/core/core_commands.py index 50e66854b..6eb2b7c9a 100644 --- a/redbot/core/core_commands.py +++ b/redbot/core/core_commands.py @@ -435,7 +435,13 @@ class Core(commands.Cog, CoreLogic): @commands.check(CoreLogic._can_get_invite_url) async def invite(self, ctx): """Show's Red's invite url""" - await ctx.author.send(await self._invite_url()) + try: + await ctx.author.send(await self._invite_url()) + except discord.errors.Forbidden: + await ctx.send( + "I couldn't send the invite message to you in DM. " + "Either you blocked me or you disabled DMs in this server." + ) @commands.group() @checks.is_owner()