From 562c30f45efa983c5f3c5c6af6ce924856b68491 Mon Sep 17 00:00:00 2001 From: Leander Furumo Date: Sun, 1 Nov 2026 20:34:43 +0100 Subject: [PATCH] only count streaks in the bot's own server Messages in other servers the bot is in and in DMs no longer count towards streaks, and catching up on missed messages at startup only reads that server. Streaks started elsewhere made /streak se look up a channel in another server, which crashed with InvalidData. Co-Authored-By: Claude Opus 5.5 --- src/cogs/streak.py | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/cogs/streak.py b/src/cogs/streak.py index 3d9e65a..c97902d 100644 --- a/src/cogs/streak.py +++ b/src/cogs/streak.py @@ -101,7 +101,7 @@ class Streak(commands.Cog): message (discord.Message): The message """ - if message.author.bot: + if message.author.bot or message.guild is None or message.guild.id != self.bot.guild_id: return self.record_message(message) @@ -143,25 +143,26 @@ class Streak(commands.Cog): await self.bot.wait_until_ready() + if not (guild := self.bot.get_guild(self.bot.guild_id)): + self.bot.logger.warning("Could not find the bot's server, so missed messages won't count towards streaks") + return + since = discord.utils.utcnow().astimezone(self.bot.timezone).replace(hour=0, minute=0, second=0, microsecond=0) counted = 0 - for guild in self.bot.guilds: - channels = [c for c in guild.channels if isinstance(c, discord.abc.Messageable)] + list(guild.threads) - for channel in channels: - if not channel.permissions_for(guild.me).read_message_history: - continue + channels = [c for c in guild.channels if isinstance(c, discord.abc.Messageable)] + list(guild.threads) + for channel in channels: + if not channel.permissions_for(guild.me).read_message_history: + continue - try: - async for message in channel.history(limit=None, after=since): - if not message.author.bot: - self.record_message(message) - counted += 1 - except discord.HTTPException as e: - self.bot.logger.warning( - f"Could not read the history of {channel} while catching up on streaks: {e}" - ) + try: + async for message in channel.history(limit=None, after=since): + if not message.author.bot: + self.record_message(message) + counted += 1 + except discord.HTTPException as e: + self.bot.logger.warning(f"Could not read the history of {channel} while catching up on streaks: {e}") - self.bot.logger.info(f"Counted {counted} messages since {since} towards streaks") + self.bot.logger.info(f"Counted {counted} messages in {guild} since {since} towards streaks") async def insert_cache(self): """