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
This commit is contained in:
Flame442 2019-08-29 21:19:19 -04:00 committed by Michael H
parent b8a7a66566
commit efcf91e934
2 changed files with 8 additions and 1 deletions

View File

@ -0,0 +1 @@
The [p]invite command no longer errors when a user has the bot blocked or DMs disabled in the server.

View File

@ -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"""
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()