Python how to quickly build a learning Wechat chat robot
This article introduces the knowledge of "how to quickly build a learning Wechat chat robot by Python". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Principle:
1. Log in, receive and send messages to WeChat account using ItChat.
2. Use ChatterBot to learn the received messages and reply the learning results as messages.
The code is as follows:
Import itchatfrom chatterbot import ChatBotfrom chatterbot.trainers import ChatterBotCorpusTrainerdeepThought = ChatBot ("deepThought") deepThought.set_trainer (ChatterBotCorpusTrainer) # training using Chinese corpora deepThought.train ("chatterbot.corpus.chinese") @ itchat.msg_register (itchat.content.TEXT) def text_reply (msg): response = deepThought.get_response (msg ['Text']) print ("from", msg [' FromUserName'], msg ['Text']) print ("to", response) itchat.send (msg=str (response) ToUserName=msg ['FromUserName']) itchat.auto_login (enableCmdQR=True) itchat.run ()
Run the program, there is a Wechat QR code, scan the code to log in
This is the end of the content of "how to quickly build a learning Wechat chat robot by Python". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!