简体   繁体   中英

Python Telegram bot doesn't react command in group chat

I made simple bot with python, that has scheduled task and sends a message if needed. I added command that starts the bot and adds the repeating task. I test it in private chat and in my own test group chat and it works. But when I try to start the bot in other group chat, it doesn't read the command. I set the privacy_mode enabled, but it didn't work. The funny think is that, it used to work before I modified the message( added some emojis), but I don't think it is that. Well here is the code:

def send_message(context: telegram.ext.CallbackContext):
    context.bot.send_message(chat_id=context.job.context, text="Hey, this bot is working")

def callback_timer(update: telegram.Update, context: telegram.ext.CallbackContext):
    context.job_queue.run_once(send_message, 1, context=update.message.chat_id)
    context.job_queue.run_repeating(send_message, 60*30, context=update.message.chat_id)

def main():
    updater = Updater(config.TOKEN, use_context=True)
    dp = updater.dispatcher
    updater.dispatcher.add_handler(CommandHandler('start_bot', callback_timer, Filters.user(username="@Test_name")))
    updater.start_polling()
    updater.idle()

if __name__ == '__main__':
    main()

The problem was that there was already other bots and somehow my bot didn't get the command. I had to use @my_bot_name to get the command, like this: /print_hello@my_bot_name

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM