import time
@itchat.msg_register(itchat.content.TEXT)
def reply_msg(msg):
print(“收到一条信息:”,msg.text)
if name == ‘main’:
itchat.auto_login()
time.sleep(5)
itchat.send(“小助手,你好呀”, toUserName=“filehelper”)
itchat.run()
效果如下:
![在这里插入图片描述](https://img-blog.csdnimg.cn/2fee3815044e4e7a9f23697226f0d3a6.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5bed5bed6I-c6bif,size_20,color_FFFFFF,t_70,g_se,x_16)
![在这里插入图片描述](https://img-blog.csdnimg.cn/a2ebda2e77004ecfb95eadd302b8f119.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5bed5bed6I-c6bif,size_20,color_FFFFFF,t_70,g_se,x_16)
四、指定某个微信好友发送消息
比如要自动给张三发送消息,代码如下:
#码登录个人微信账号
import itchat
itchat.auto_login