Fixed [p]announce failing due to errors messaging the owner. (#3166)

* Fixed owner message behavior

* Create 3166.bugfix.rst

* Reduce messages

* Fix plurality
This commit is contained in:
Flame442 2019-12-08 18:04:57 -05:00 committed by Michael H
parent 203cde9805
commit 8cba47f382
2 changed files with 11 additions and 4 deletions

View File

@ -0,0 +1 @@
Fixed ``[p]announce`` failing after encountering an error attempting to message the bot owner.

View File

@ -3,6 +3,7 @@ import asyncio
import discord
from redbot.core import commands
from redbot.core.i18n import Translator
from redbot.core.utils.chat_formatting import humanize_list, inline
_ = Translator("Announcer", __file__)
@ -53,7 +54,7 @@ class Announcer:
async def announcer(self):
guild_list = self.ctx.bot.guilds
bot_owner = (await self.ctx.bot.application_info()).owner
failed = []
for g in guild_list:
if not self.active:
return
@ -66,9 +67,14 @@ class Announcer:
try:
await channel.send(self.message)
except discord.Forbidden:
await bot_owner.send(
_("I could not announce to server: {server.id}").format(server=g)
)
failed.append(str(g.id))
await asyncio.sleep(0.5)
msg = (
_("I could not announce to the following server: ")
if len(failed) == 1
else _("I could not announce to the following servers: ")
)
msg += humanize_list(tuple(map(inline, failed)))
await self.ctx.bot.send_to_owners(msg)
self.active = False