Troubleshooting Guide¶
This guide helps you diagnose and fix common issues with aiogram-cmds.
🚨 Common Issues¶
Commands Not Appearing in Telegram¶
Symptoms: - Commands don't show up in the Telegram menu - Users can't see bot commands - Commands work when typed manually but not in menu
Possible Causes:
-
Not calling setup_all()
-
Invalid bot token
-
Invalid command names
# ❌ Invalid command names commands = { "Start Bot": CommandDef(...), # Spaces not allowed "help-me": CommandDef(...), # Hyphens not allowed "123start": CommandDef(...), # Can't start with number } # ✅ Valid command names commands = { "start": CommandDef(...), # Lowercase, letters only "help": CommandDef(...), # Valid "start_bot": CommandDef(...), # Underscores allowed } -
Command name too long
Debug Steps:
import logging
logging.basicConfig(level=logging.DEBUG)
# Check if setup_all() is called
manager = CommandScopeManager(bot)
await manager.setup_all() # Should log success messages
i18n Translations Not Working¶
Symptoms: - Commands show fallback descriptions instead of translations - Translations work in some languages but not others - Translation keys not found
Possible Causes:
-
Missing translator setup
-
Incorrect translation key pattern
-
Missing translation files
-
Translation files not compiled
Debug Steps:
# Test translator directly
translator = build_translator_from_i18n(i18n)
result = translator("cmd.start.desc", locale="en")
print(f"Translation result: {result}")
# Check i18n instance
print(f"i18n instance: {i18n}")
print(f"Available locales: {i18n.available_locales}")
Profile Resolver Not Working¶
Symptoms: - Users get wrong command sets - Profile changes don't update commands - All users get the same commands
Possible Causes:
-
Profile resolver not returning valid profiles
-
Profile not defined in configuration
-
Not calling update_user_commands()
Debug Steps:
# Test profile resolver
def test_resolver(flags: Flags) -> str:
profile = my_resolver(flags)
print(f"Flags: {flags}, Profile: {profile}")
return profile
# Check profile definitions
config = CmdsConfig(...)
print(f"Available profiles: {list(config.profiles.keys())}")
Dynamic Command Updates Not Working¶
Symptoms: - Commands don't update after user actions - Users still see old commands - Profile changes don't reflect in commands
Possible Causes:
-
Not calling update_user_commands()
-
Profile resolver not using updated state
# ❌ Resolver uses old state def resolver(flags: Flags) -> str: # This might use cached or old user data return get_profile_from_database(user_id) # ✅ Resolver uses current state def resolver(flags: Flags) -> str: user_id = getattr(flags, 'user_id', None) current_state = get_current_user_state(user_id) return determine_profile(current_state) -
Telegram API rate limits
Debug Steps:
# Log command updates
async def debug_update_commands(user_id: int, **flags):
print(f"Updating commands for user {user_id} with flags: {flags}")
await manager.update_user_commands(user_id, **flags)
print(f"Commands updated for user {user_id}")
Import Errors¶
Symptoms:
- ModuleNotFoundError: No module named 'aiogram_cmds'
- Import errors when running the bot
- Version conflicts
Possible Causes:
-
aiogram-cmds not installed
-
Wrong Python environment
-
Version conflicts
Debug Steps:
# Test import
try:
import aiogram_cmds
print(f"aiogram-cmds version: {aiogram_cmds.__version__}")
except ImportError as e:
print(f"Import error: {e}")
Bot Not Responding¶
Symptoms: - Bot doesn't respond to messages - Commands work but bot is silent - Bot appears offline
Possible Causes:
-
Invalid bot token
-
Bot not running
-
Message handlers not registered
-
Middleware blocking messages
Debug Steps:
# Test bot connection
async def test_connection():
try:
me = await bot.get_me()
print(f"Bot connected: {me.username}")
except Exception as e:
print(f"Connection error: {e}")
# Test message handling
@dp.message()
async def debug_handler(message: Message):
print(f"Received message: {message.text}")
await message.answer("Bot is working!")
🔧 Debugging Tools¶
Enable Debug Logging¶
import logging
# Enable debug logging
logging.basicConfig(level=logging.DEBUG)
# Or for specific loggers
logging.getLogger("aiogram_cmds").setLevel(logging.DEBUG)
logging.getLogger("aiogram").setLevel(logging.DEBUG)
Test Configuration¶
def test_configuration():
"""Test your configuration."""
try:
config = CmdsConfig(
languages=["en", "ru"],
commands={
"start": CommandDef(i18n_key="start.desc"),
"help": CommandDef(i18n_key="help.desc"),
},
profiles={
"user": ProfileDef(include=["start", "help"]),
},
scopes=[
ScopeDef(scope="all_private_chats", profile="user"),
],
)
print("✅ Configuration is valid")
return config
except Exception as e:
print(f"❌ Configuration error: {e}")
return None
Test Profile Resolver¶
def test_profile_resolver():
"""Test your profile resolver."""
resolver = my_profile_resolver
test_cases = [
Flags(is_registered=False, has_vehicle=False),
Flags(is_registered=True, has_vehicle=False),
Flags(is_registered=True, has_vehicle=True),
]
for flags in test_cases:
try:
profile = resolver(flags)
print(f"Flags: {flags} → Profile: {profile}")
except Exception as e:
print(f"❌ Resolver error: {e}")
Test Command Building¶
async def test_command_building():
"""Test command building."""
from aiogram_cmds import build_bot_commands
commands = build_bot_commands(
["start", "help"],
lang="en",
translator=my_translator
)
for cmd in commands:
print(f"Command: {cmd.command}, Description: {cmd.description}")
Test Translator¶
def test_translator():
"""Test your translator."""
translator = build_translator_from_i18n(i18n)
test_keys = [
"cmd.start.desc",
"cmd.help.desc",
"cmd.profile.desc",
]
for key in test_keys:
for lang in ["en", "ru", "es"]:
result = translator(key, locale=lang)
print(f"{key} ({lang}): {result}")
🚨 Error Messages¶
Common Error Messages and Solutions¶
ValidationError: field required¶
❌ Error: ValidationError: field required
✅ Solution: Check that all required fields are provided in your configuration
ValueError: Unknown scope: invalid_scope¶
❌ Error: ValueError: Unknown scope: invalid_scope
✅ Solution: Use valid scope types: default, all_private_chats, all_group_chats, etc.
KeyError: 'profile_name'¶
❌ Error: KeyError: 'profile_name'
✅ Solution: Make sure the profile is defined in your configuration
TypeError: 'NoneType' object is not callable¶
❌ Error: TypeError: 'NoneType' object is not callable
✅ Solution: Check that your translator function is properly defined
📞 Getting Help¶
Before Asking for Help¶
- Check the logs - Enable debug logging and check for error messages
- Test your configuration - Use the debugging tools above
- Check the documentation - Review the relevant guides
- Search existing issues - Check GitHub issues for similar problems
When Asking for Help¶
Provide the following information:
- Error message - Full error traceback
- Code snippet - Minimal code that reproduces the issue
- Configuration - Your configuration (without sensitive data)
- Environment - Python version, aiogram version, aiogram-cmds version
- Steps to reproduce - Clear steps to reproduce the issue
Where to Get Help¶
- GitHub Discussions - Community help
- GitHub Issues - Bug reports
- Documentation - Complete guides
Still having issues? Check out our FAQ or create an issue with the information above!