fix: check_self wywala się na starcie, gdy kanał = None #13

Merged
gitea merged 1 commits from fix-check-self-none-channel into main 2026-08-02 17:01:39 +00:00
+18
View File
@@ -171,6 +171,17 @@ class AdministrationModule(commands.Cog):
"""
# logger.info("Heartbeat of cleanup proc")
channel = self.bot.get_channel(1062047367337095268)
if channel is None:
# get_channel() returns None before the gateway cache is populated
# (the before_loop below normally prevents that) or when the bot
# cannot see the channel at all (wrong id / not in the guild /
# missing permission). Skip this tick instead of crashing - an
# unhandled exception here stops the whole loop, killing log
# rollover and the spontaneous messages with it.
self.logger.warning(
"check_self: channel 1062047367337095268 unavailable - skipping tick"
)
return
messages = [message async for message in channel.history(limit=1)]
for mess in messages:
channel = mess.channel
@@ -254,6 +265,13 @@ class AdministrationModule(commands.Cog):
self.logger.info(message)
await channel.send(message)
@check_self.before_loop
async def before_check_self(self):
# Don't fire the first tick until the gateway is READY and the channel
# cache is populated - get_channel() returns None before that, which is
# exactly what used to crash check_self at startup.
await self.bot.wait_until_ready()
async def setup(bot):
logger = logging.getLogger("discord")