Reputation: 11
So, I'm kinda new creating bots with Python. I'm using PyPI(PY Telegram Bot). I've been learning a lot during these days and it even started working. While using MessageHandler I could pretty much send a message and the bot would return me a text or a picture.
But now I want something different. I want to start creating a game for Telegram, still to learn more on how to use the library.
The thing is: eveytime I want the bot to answer me, it doesn't work. Basically when entering the rockpaperscissors function, I want it to show a text asking for an option, then, whatever this answer is leads me to an answer by the bot. But whenever I answer, the bot never answers back.
Just an example of what happens:
And here is the source code. I excluded the superfluous sections so it wouldn't be that messy. Any help is appreciated :)
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, ConversationHandler, CallbackContext
import random
def rockpaperscissors(update, context):
update.message.reply_text('Rock, paper, scissors. Return an option')
msgUsr = str(update.message.text)
if msgUser == "rock":
update.message.reply_text("You chose 'rock'")
def main():
token ='(token)'
updater = Updater(token=token, use_context=True)
dispatcher.add_handler(CommandHandler('rps',rockpaperscissors))
updater.start_polling()
updater.idle()
if __name__ == "__main__":
main()
Upvotes: 1
Views: 1488
Reputation: 1221
Your bot is expecting a command /rps
, and responding correctly. However, when you send a plain message (rather than a command), the bot just doesn't know what to do. Note that the function rockpaperscissors
is only called when the user sends a message starting with /rps
or /rps@yourbot
, but it never equals to "rock". So your if
will never be executed.
You must add a MessageHandler
and associate another function to, well, handle the message.
Upvotes: 1