Get the App
SLTechnology News&Howtos  ›  Development  › 

How does Python make Wechat Robot

Shulou Source: shulou.com Published: 2022-06-02 05:15:33 10月02日 Update

In this issue, Xiaobian will bring you about how Python makes WeChat robots. The article is rich in content and analyzes and narrates from a professional perspective. After reading this article, I hope you can gain something.

I. Environmental configuration

Most people can't log in to the web version, so bypass it to simulate computer login, and remember to install this module:

pip install itchat-uosip install itchat II. Login #code to log in to personal WeChat account import itchatitchat.auto_login(hotReload=True)#hotReload= True You can temporarily store the login status. After exiting, restart within a certain time without scanning the code again. Third, the first simple message sent monitoring

For example, send a message to the file transfer assistant and monitor it in real time. Code:

# coding=gbk"" Author: Chuan Chuan @ Time: 2021/12/24 15:59""import itchatimport time@itchat.msg_register(itchat.content.TEXT)def reply_msg(msg): print("Received a message: ",msg.text)if __name__== '__main__': itchat.auto_login() time.sleep(5) itchat.send("Hello, little helper", toUserName="filehelper") itchat.run()

The effects are as follows:

IV. Specify a WeChat friend to send a message

For example, to automatically send a message to Zhang San, the code is as follows:

#Code login personal WeChat account import itchatitchat.auto_login(hotReload=True)#hotReload= True You can temporarily store the login status, and restart it within a certain period of time after exiting without scanning the code again.# itchat.auto_login(hotReload=True)friends_list =itchat.get_friends(update=True)users =itchat.search_friends(name=u'Zhang San') userName = users[0]["UserName"]itchat.send ('Testing WeChat bots... ' ,toUserName = userName)

Effect:

V. Monitoring of all WeChat groups

The effect is as follows: (individual remarks I mosaic)

Test results:

VI. Public number monitoring

Effect:

This is to monitor all public accounts, designated to my own public account: Chuan Chuan rookie sends messages

VII. Send messages regularly

For example, remember to remind a big lazy bug to eat every day, and execute it at twelve o 'clock every day:

# coding=gbk"" Author: Chuan Chuan @ Time: 2021/12/24 16:26 Group: 970353786""import itchatfrom apscheduler.schedulers.blocking import BlockingScheduler#Send message def send_msg(): user_info = itchat.search_friends(name='Little Bell') if len(user_info) > 0: user_name = user_info[0]['UserName'] itchat.send_msg ('Remember to eat, lazy worm! ', toUserName=user_name)def after_login(): #The current mission will be executed at twelve o'clock every day of the month sched.add_job(send_msg, 'cron', month='*', day='*', hour='12') sched.start()def after_logout(): sched.shutdown()if __name__ == '__main__': sched = BlockingScheduler() itchat.auto_login(loginCallback=after_login, exitCallback=after_login,hotReload=True) itchat.run()

No, the code is correct.

VIII. WeChat intelligent chat robot

The effect is:

The above is how Python shared by Xiaobian for everyone makes WeChat robots. If there are similar doubts, please refer to the above analysis for understanding. If you want to know more about it, please pay attention to the industry information channel.

Tags: Login messages effects machines robots time code public Sichuan monitoring production no personal author information content again assistants friends slackers Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS MariaDB NVidia Shulou Technology Docker