0

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-9\s]", ' ', 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) 
2
  • wrong indentation level on the last if? it is executed only if not joke_text Commented Sep 7, 2016 at 13:38
  • When I put the last if to the begin, bot will send both if statements ( not joke_text and last if ). Commented Sep 7, 2016 at 13:44

3 Answers 3

4
if 'No': 

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

Sign up to request clarification or add additional context in comments.

2 Comments

Good point! I have tried to put [if recevied_message == 'No':] on that before but it still sent "I didn't understand..." of the above if back
Oke I realize that I am a noob. I just can switch the position of the if received_message == 'No': before the other if. It worked for me! Thank you very much!
0

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.

Comments

0

'No' is a string.

if 'No' 

always return True.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.