diff --git a/bot.py b/bot.py index f911f3a..27568cd 100644 --- a/bot.py +++ b/bot.py @@ -199,11 +199,27 @@ class GravityBot(commands.Bot): return self.project_channels[project_name] async with self._channel_lock: - # Double-check + # Double-check after lock if project_name in self.project_channels: return self.project_channels[project_name] channel_name = self._make_channel_name(project_name) + + # Search existing channels FIRST (prevents duplicates) + try: + all_channels = await self.guild.fetch_channels() + for ch in all_channels: + if (isinstance(ch, discord.TextChannel) + and ch.name == channel_name + and ch.category_id == self.session_category.id): + self.project_channels[project_name] = ch + self.channel_to_project[ch.id] = project_name + logger.info(f"Found existing channel: #{channel_name}") + return ch + except Exception as e: + logger.warning(f"fetch_channels failed: {e}") + + # No existing channel — create new try: ch = await self.guild.create_text_channel( name=channel_name,