From 8cba47f382d086330bb225231206f3bdb83cacb7 Mon Sep 17 00:00:00 2001 From: Flame442 <34169552+Flame442@users.noreply.github.com> Date: Sun, 8 Dec 2019 18:04:57 -0500 Subject: [PATCH] Fixed [p]announce failing due to errors messaging the owner. (#3166) * Fixed owner message behavior * Create 3166.bugfix.rst * Reduce messages * Fix plurality --- changelog.d/admin/3166.bugfix.rst | 1 + redbot/cogs/admin/announcer.py | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 changelog.d/admin/3166.bugfix.rst diff --git a/changelog.d/admin/3166.bugfix.rst b/changelog.d/admin/3166.bugfix.rst new file mode 100644 index 000000000..532d4d6d0 --- /dev/null +++ b/changelog.d/admin/3166.bugfix.rst @@ -0,0 +1 @@ +Fixed ``[p]announce`` failing after encountering an error attempting to message the bot owner. diff --git a/redbot/cogs/admin/announcer.py b/redbot/cogs/admin/announcer.py index 154eacb48..0a9dac2a2 100644 --- a/redbot/cogs/admin/announcer.py +++ b/redbot/cogs/admin/announcer.py @@ -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