Skip to content

Improve error handling for missing DISCORD_TOKEN #7

@TrivCodez

Description

@TrivCodez

Description

Enhance the error handling when the DISCORD_TOKEN environment variable is missing or invalid.

Current Behavior

The bot currently raises a generic RuntimeError with minimal guidance.

Desired Behavior

Provide clear, actionable error messages that guide users to:

  1. Check if .env file exists
  2. Verify token format
  3. Provide setup instructions

Task

  • Modify bot.py error handling section
  • Add specific error messages for different failure cases
  • Include helpful links or instructions

Why this is good for beginners

  • Teaches proper error handling patterns
  • Improves user experience
  • Simple string/validation logic
  • No external dependencies

Files to modify

  • bot.py (lines 11-13)

Example improved error message

if not TOKEN:
    raise RuntimeError(
        "DISCORD_TOKEN not found!\n"
        "1. Copy .env.example to .env\n"
        "2. Replace YOUR_BOT_TOKEN_HERE with your bot token\n"
        "3. Get a token from https://discord.com/developers/applications"
    )

Acceptance Criteria

  • Clear error message for missing token
  • Validation for token format (basic check)
  • Actionable steps provided
  • Error occurs before bot initialization
  • Code includes comments explaining the validation

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationenhancementNew feature or requestgood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions