skip to Main Content

I’m new to django python so the if makes me feel confused. Please help me!

Im trying to make a IF condition for Facebook chat bot API. The whole function is when a user sends something in the Facebook chat, my bot will remove all punctuations, lower case the text and split it based on space.
After that he will pick a joke from json list with the keyword he got. A quick reply with 2 buttons “Yes” and “No” is also sent to user with the joke.

It also checks if the keyword is absent. Now I want that when user types “No” in the chat, my bot will send something back like “Then not”. What did I do wrong here?

strong texttokens = re.sub(r"[^a-zA-Z0-9s]", ' ', recevied_message).lower().split()
joke_text = ''
for token in tokens:
    if token in jokes:
        joke_text = random.choice(jokes[token])

        .... some code

        send_message(fbid, joke_text)

        quick_text = "Do you want another joke? "
        send_quick_reply_message(fbid, quick_text)
        break
if not joke_text:
    joke_text = "I didn't understand! " 
                "Send 'stupid', 'fat', 'dumb' for a Yo Mama joke!"
    send_message(fbid, joke_text)
    if 'No':
        joke_text = "Then not"
        send_message(fbid, joke_text)

3

Answers


  1. if 'No': 
    

    is always true, you probably want to be checking if something == ‘No’?

    Login or Signup to reply.
  2. I think this code have a problem

     if 'No':
        joke_text = "Then not"
        send_message(fbid, joke_text)
    

    What is ‘No”? You have to compare something with “No”.
    And also this if condition is on wrong indentation level.

    Login or Signup to reply.
  3. ‘No’ is a string.

    if 'No'  
    

    always return True.

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