Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 3, 2026

Commands were executing twice because the LinkManager cog's on_message handler explicitly called bot.process_commands(), duplicating Discord.py's automatic command processing.

Changes

  • Removed redundant process_commands() call in LinkManager.on_message (line 534)

    • Discord.py handles command processing automatically; explicit call caused double execution
    • Added comment documenting why the call was removed
  • Added documentation in main() function

    • Documented why cog registration happens inside main() rather than at module level
    • Prevents future duplicate registration issues

Before

@commands.Cog.listener()
async def on_message(self, message):
    if message.author == self.bot.user or message.id in self.processed_messages:
        return
    
    self.processed_messages.add(message.id)
    await self.bot.process_commands(message)  # Duplicate processing
    # ... rest of handler

After

@commands.Cog.listener()
async def on_message(self, message):
    if message.author == self.bot.user or message.id in self.processed_messages:
        return
    
    self.processed_messages.add(message.id)
    # NOTE: Do NOT call bot.process_commands() here - Discord.py handles this automatically
    # Calling it here would cause all commands to execute twice
    # ... rest of handler

Commands and help now execute once per invocation.

Original prompt

Fix duplicate command execution by ensuring the LinkManager cog is only added once and removing other duplicate listeners.

Context:

  • Users report every command (and help) executes twice (see images). This is caused by the cog being added twice and/or multiple on_message handlers running.
  • The repository "Rajrooter/Discord-Link-manager-Bot" currently adds the LinkManager cog more than once (top-level and again inside main()).

Requested changes:

  1. Update main.py to ensure the LinkManager cog is added exactly once.
    • Remove the duplicate top-level bot.add_cog(LinkManager(bot)) call so the cog is only added inside the main() function before starting the bot.
    • Alternatively, if cog is added at top-level keep it and remove the add inside main(); prefer adding inside main() to avoid side-effects on import.
  2. Make sure there's only one bot = commands.Bot(...) instance and no other top-level event listeners that call bot.process_commands outside the cog.
  3. Add brief comment in main.py explaining why the cog is added only inside main() to avoid duplicate listeners.
  4. Run a quick sanity change so that the help_command is consistent (if top-level help_command is None but earlier file used AdorableHelp, keep the bot configured to use AdorableHelp when creating the Bot instance).

Include uploaded images for context: image1 image2 image3

Files to modify:

  • main.py: remove duplicate add_cog line and add explanatory comment; ensure only one add_cog call exists (inside main()).

NOTE: Do not modify other functionality. Keep deletions wrapped in try/except as before. Do not include any secrets in the PR. After change, commands should execute only once.

This pull request was created from Copilot chat.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…ents

Co-authored-by: Rajrooter <128113526+Rajrooter@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix duplicate command execution in LinkManager cog Fix duplicate command execution from redundant process_commands call Jan 3, 2026
Copilot AI requested a review from Rajrooter January 3, 2026 22:07
@Rajrooter Rajrooter marked this pull request as ready for review January 3, 2026 22:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants