skip to Main Content

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.

2

Answers


  1. Chosen as BEST ANSWER

    I've daclared a boolean variable and when i get the command it's been set to True and declared end function to set the boolean False when the function called and i put if statement for every message handled to check if send command has called.


  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search