我想用telethon python发出自动回复消息。但是当我跑步时,它无法收到消息,也无法回复我的消息。
这是我的代码。任何人都可以帮助我
def chatbot_response(msg):
ints = predict_class(msg, model)
res = getResponse(ints, intents)
return res
if __name__ == '__main__':
# Create the client and connect
# use sequential_updates=True to respond to messages one at a time
client = TelegramClient(session_file, api_id, api_hash, sequential_updates=True)
@client.on(events.NewMessage(incoming=True))
async def handle_new_message(event):
if event.is_private: # only auto-reply to private chats
from_ = await event.client.get_entity(event.from_id)
if not from_.bot: # don't auto-reply to bots
msg = events.NewMessage(incoming=True)
if msg!='':
message= cchatbot_response(msg)
print(time.asctime(), '-', event.message) # optionally log time and message
time.sleep(1) # pause for 1 second to rate-limit automatic replies
await event.respond(message)
print(time.asctime(), '-', 'Auto-replying...')
client.start(phone, password)
client.run_until_disconnected()
答案 0 :(得分:0)
我可以在减去这些行的情况下运行您的代码
message = cchatbot_response(msg)
print(time.asctime(), '-', event.message) # optionally log time and message
time.sleep(1) # pause for 1 second to rate-limit automatic replies
请检查cchatbot_response函数。
我也打了这条线
client.start(phone, password)
像这样
client.start()
它提示我输入我的电话号码和密码,但没有再提及。