mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -05:00
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:
parent
203cde9805
commit
8cba47f382
1
changelog.d/admin/3166.bugfix.rst
Normal file
1
changelog.d/admin/3166.bugfix.rst
Normal file
@ -0,0 +1 @@
|
||||
Fixed ``[p]announce`` failing after encountering an error attempting to message the bot owner.
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user