@dp.messagehandler(Text(equals="❓ Помощь", ignorecase=True)) - String.init() got an…
- User
@dp.message_handler(Text(equals="❓ Помощь", ignore_case=True)) - String.init() got an unexpected keyword argument 'equals'
- Assistant
@dp.message_handler(Text(equals="❓ Помощь", ignore_case=True)) - String.init() got an unexpected keyword argument 'equals'
It looks like you're encountering a TypeError when trying to use the Text filter in your aiogram bot. The error message:
String.__init__() got an unexpected keyword argument 'equals'
suggests that Python is trying to initialize a String object with an unexpected keyword argument equals. This typically happens when the Text filter is not correctly imported or is being overshadowed by another Text class (like Python's built-in str or another library's Text).
Incorrect Import of the Text Filter
In aiogram, the Text filter should be imported from aiogram.dispatcher.filters (or aiogram.filters depending on the version you are using). If you mistakenly import Text from another module or if there's a naming conflict, Python might be referencing a different Text class that doesn't accept the equals keyword argument.
Ensure Correct Import of Text Filter
Make sure you're importing the Text filter from aiogram.dispatcher.filters (for aiogram versions < 3) or from aiogram.filters (for aiogram v3 and above).
For aiogram v2:
from aiogram.dispatcher.filters import Text
For aiogram v3:
from aiogram.filters import Text
Avoid importing Text from other modules, such as Python's built-in str or other libraries, which do not support the equals keyword argument.
Check for Naming Conflicts
Ensure that there's no other class or variable named Text in your code that might be overshadowing the aiogram's Text filter.
# Avoid doing something like this before using the Text filter
Text = "Some string or another class"
Example Usage
Here's a complete example of how to use the Text filter correctly in an aiogram bot:
from aiogram import Bot, Dispatcher, types
from aiogram.contrib.middlewares.logging import LoggingMiddleware
from aiogram.dispatcher.filters import Text # For aiogram v2
# from aiogram.filters import Text # For aiogram v3
import logging
import asyncio
API_TOKEN = 'YOUR_BOT_TOKEN_HERE'
# Configure logging
logging.basicConfig(level=logging.INFO)
# Initialize bot and dispatcher
bot = Bot(token=API_TOKEN)
dp = Dispatcher(bot)
dp.middleware.setup(LoggingMiddleware())
@dp.message_handler(Text(equals="❓ Помощь", ignore_case=True))
async def send_help(message: types.Message):
await message.reply("Это раздел помощи!")
async def main():
await dp.start_polling()
if __name__ == '__main__':
asyncio.run(main())
Verify aiogram Version
Ensure you're using a compatible aiogram version that supports the Text filter with the equals and ignore_case parameters.
For aiogram v2:
pip install aiogram==2.x
For aiogram v3:
pip install aiogram==3.x
Check your aiogram version with:
import aiogram
print(aiogram.__version__)
Additional Tips
Use Exact Matching Carefully: The Text filter with equals performs exact matching. Ensure that the message content exactly matches "❓ Помощь". Any additional spaces or characters will prevent the handler from being triggered.
Debugging Imports:
You can add a print statement to confirm which Text is being used.
from aiogram.dispatcher.filters import Text # Adjust import based on version
print(Text) # Should reference aiogram's Text filter
If it doesn't reference the correct Text class, revisit your imports.
The error you're encountering is likely due to importing the wrong Text class or a naming conflict overshadowing the aiogram's Text filter. Ensure that you import Text from the correct aiogram module and avoid naming conflicts in your code. This should resolve the TypeError related to the unexpected equals keyword argument.
If you continue to experience issues, please provide more context or additional code snippets so I can assist you further.