iT邦幫忙

0

在問一個Python問題 (LINE機器人)

  • 分享至 

  • xImage

https://ithelp.ithome.com.tw/upload/images/20190628/20118473lcVaDgjZ9Q.png

我個人已經完成了她會照著我所說的話去執行動作了 如果我還需要其他功能的話要如何保存上面的設定之下在另外的新增其他指令呢?

柯柯 iT邦新手 3 級 ‧ 2019-06-28 16:15:55 檢舉
怎不要 把url 存到Array裡面
然後這樣寫
```
message = ImageSendMessage(
original_content_url = Url[i] ,
preview_image_url = Url[i]
);
```

回題 最外層的IF 再新增 else 去判斷他message.text = "其他"
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

2
dragonH
iT邦超人 5 級 ‧ 2019-06-28 00:24:19

首先你必須了解 if 語句的用法

了解後就可以照你想要的修改

if event.message.text == '#小劇場':
...
elif event.message.text == '#大劇場':
...

大概這樣

看更多先前的回應...收起先前的回應...
s0438 iT邦新手 5 級 ‧ 2019-06-28 00:28:47 檢舉

不太懂你的意思

s0438 iT邦新手 5 級 ‧ 2019-06-28 00:28:47 檢舉

不太懂你的意思

ant1017 iT邦新手 2 級 ‧ 2019-06-28 08:07:21 檢舉

怎麼PYTHON的IF ELSE跟SWITCH CASE很像@@

dragonH iT邦超人 5 級 ‧ 2019-06-28 09:08:57 檢舉

呃...

event.message.text 就是在line輸入的關鍵字

if event.message.text == '#小劇場' 的意思是

如果(if)輸入的關鍵字(event.message.text)等於 #小劇場 時

就執行底下的動作

elif 的意思是 else if

也就是有 或者如果 的意思

所以我的意思就是用 if ... elif 去判斷你多個關鍵字

分別去執行符合條件時所執行的動作

看這情況就先不提 switch 了


ant1017

應該都大同小異啦 XD

如果是指

if:

elif:

的話

應該是說 python 的寫法就這樣/images/emoticon/emoticon12.gif

froce iT邦大師 1 級 ‧ 2019-06-30 18:43:58 檢舉

pythonic的寫法:

def f(x):
    return {
        'a': 1,
        'b': 2,
    }[x]

elif太繁複了,通常會用在真的還有其他邏輯要表達,用在switch的比較少。

我要發表回答

立即登入回答