name 'events' is not defined

75 Views Asked by At

Actually, I'm a beginner in python,I'm making a linebot and and I want to make a feature that can send back the ButtonsTemplate I made after detecting a keyword,I'm not sure if there are other bugs in my code,But when I run my code, it says event is not defined.I have written line_token and line_secret in the program, but I don't show them here.The last 7 lines are where the error occurs.Thanks. This is the full code that it wrote:

from linebot import LineBotApi, WebhookHandler

from linebot.models import PostbackAction,URIAction, MessageAction, TemplateSendMessage, ButtonsTemplate
line_bot_api = LineBotApi('')
handler = WebhookHandler('')
class Eatmodel():
def content(self):
template_message = TemplateSendMessage(
line_bot_api.push_message('U821215adb9a791364df34bdc4d5e96fb',

TemplateSendMessage(
alt_text='ButtonsTemplate',
template=ButtonsTemplate(
title='Eat點通-常見問題',
text='選擇問題',
actions=\[
MessageAction(
label='會員問題',
text='會員問題'
),
MessageAction(
label='食譜問題',
text='食譜問題'
),
MessageAction(
label='健康小知識',
text='健康小知識'
),
MessageAction(
label='廚房小知識',
text='廚房小知識'
)
\]
)
))
)
return template_message

for event in events:
if isinstance(event, MessageEvent):  # 如果有訊息事件
if event.message.text == "home":
line_bot_api.reply_message(  # 回復傳入的*your text*訊息文字
event.reply_token,
Eatmodel().content()
)
1

There are 1 best solutions below

0
On

I think that the problem in this situation is that events is not defined, leading to the program being unable to run the loop. For more information on for loops, Check out this link