Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Python how to quickly build a learning Wechat chat robot

Shulou Source: shulou.com Published: 2022-06-01 19:11:09 09月12日 Update

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!

Tags: Learning messages machines robots content more knowledge login practicality learning and then code signals principles dilemmas reality situations articles cases programs Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Linux Huawei Xiaomi vpn