I’m new to making Telegram bots with Python. I want to send messages at set times but I’m having trouble. The callback_minute function doesn’t seem to work right with multiple arguments. I’ve looked at examples and docs for the run_repeating function but I’m stuck.
I’ve been through this exact issue when setting up scheduled messages for my Telegram bot. The problem is likely with how you’re passing the callback function to run_repeating.
Notice I removed ‘self’ from the function definition and call. This should resolve the ValueError you’re seeing.
For getting the chat_id dynamically, you could store it in context.bot_data when the bot first interacts with a chat, then retrieve it in the callback. Something like:
This approach passes the chat_id as context to the job, making it accessible within the callback function. It’s more flexible as you can easily change the chat_id for different jobs.
For dynamic chat_ids, consider storing them in a database or configuration file, then retrieve them when setting up the job queue. This allows for easier management of multiple chats and schedules.