Skip to content

Conversation

@NNTin
Copy link
Contributor

@NNTin NNTin commented Nov 21, 2025

Analysis of the problem

Problem Analysis

Based on the error traceback and codebase investigation, here's what's happening:

The Error

AttributeError: 'Red' object has no attribute '_AutoShardedClient__queue'. Did you mean: '_AutoShardedClient__shards'?

This error occurs during the bot shutdown process when red.close() is called. The issue is that the Red class (which inherits from discord.ext.commands.AutoShardedBot) is trying to access an internal attribute __queue that doesn't exist.

Root Cause

The problem stems from the mixin initialization order in the Red class:

class Red(
    commands.GroupMixin, RPCMixin, dpy_commands.bot.AutoShardedBot
):

Looking at the initialization chain:

  1. Red.init (line 104-241 in bot.py) does extensive setup work BEFORE calling super().init() at line 241

  2. RPCMixin.init (line 144-146 in _rpc.py) calls super().init(**kwargs)

  3. commands.GroupMixin doesn't define init, so it passes through

  4. Finally reaches AutoShardedBot.init which sets up internal attributes like __queue

The issue is that during the --dry-run execution:

  • The bot starts initialization

  • At line 366 in main.py, when --dry-run is detected, it calls sys.exit(ExitCodes.SHUTDOWN)

  • This triggers the shutdown handler at line 539

  • The shutdown handler calls await red.close() at line 441

  • But red.close() → super().close() (line 2278 in bot.py) tries to access AutoShardedClient's internal __queue attribute

  • This attribute was never properly initialized because the initialization was interrupted

Why This Happens Specifically with --dry-run

The --dry-run flag causes an early exit at line 365-366 in main.py:

if cli_flags.dry_run:
    sys.exit(ExitCodes.SHUTDOWN)

This happens before await red.start(token) is called (line 369), which means:

  • The bot's connection lifecycle never begins

  • Discord.py's internal sharding infrastructure (including __queue) is never fully initialized

  • But the shutdown handler still tries to call close() which expects these internals to exist

try, catch might not be the best solution but I can't think of a better one. This only happens when it is not fully initialized and thus sharding is not possible.

closes #6572
the original issue is also addressed.

PS C:\privat\codex\Red-DiscordBot> python -m redbot --no-prompt
Error: No instance name was provided!
PS C:\privat\codex\Red-DiscordBot> python -m redbot --no-prompt tinkerer
Instance with name 'tinkerer' doesn't exist. You can create new instance using `redbot-setup` prior to running the bot.

@github-actions github-actions bot added the Category: Core - Bot Class This is related to the `redbot.core.bot.Red` class. label Nov 21, 2025
@github-actions github-actions bot added the Category: Meta This is related to the repository maintenance. label Nov 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Category: Core - Bot Class This is related to the `redbot.core.bot.Red` class. Category: Meta This is related to the repository maintenance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Starting a bot with missing configuration may exit with code 1 instead of expected 78

1 participant