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