简体   繁体   中英

python-telegram-bot handle message only after command

I'm trying to let bot send the message that i gave him by first sending /send_m command then it will ask for the message after that i write the message it will send it to other users, the problem is that message handler is running send function even if I didn't give it /send_m command how can i fix this issue?

dispatcher = updater.dispatcher
dispatcher.add_handler(CommandHandler('send', send_m))
dispatcher.add_handler(MessageHandler(Filters.text,send))
updater.start_polling()

I'm handling messages and commands like this.

我已经声明了一个布尔变量,当我得到命令时,它被设置为True并声明结束函数以在函数调用时将布尔值设置为False ,并且我为处理的每条消息放置 if 语句以检查发送命令是否已调用。

dispatcher.add_handler(MessageHandler(Filters.text,send & ~Filters.command, send))

You may notice that MessageHandler is used instead of CommandHandler. This is a more general handler that selects messages based off flags that you supply. In this case, it handles messages that contain text but aren't commands

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