DevsDawn
DevsDawn

用itchat做一个简单的关键词回复微信机器人

itchat组件:https://github.com/littlecodersh/ItChat
下载后根据安装教程安装itchat

pip install itchat

新建wxbot.py

#coding=utf8
import itchat
import time
@itchat.msg_register('Text')
def text_reply(msg):
    f = open("words.txt")  
    for line in f:
        splited = line.split(',')
        if splited[0] in msg['Text']:
            return splited[1].replace("\n", "")
        f.close()
        itchat.auto_login(True, enableCmdQR=True)
        itchat.run()

新建words.txt(注意文件编码,否则会导致乱码)
用以下格式编辑关键词回复

关键词1,回复1
关键词2,回复2
关键词3,回复3

运行

python wxbot.py

登录后即可。

若无特别说明,本文采用 CC BY-SA 4.0 协议进行许可。如需转载,请附上本文链接和本声明。
本文链接:https://devsdawn.com/2017/06/using-itchat-to-make-a-simple-wechat-robot/
DigitalOcean云服务,美国上市公司,注册即送200USD体验金
Vultr云服务,全球25+地域,注册即送100USD体验金
#
首页      开发      用itchat做一个简单的关键词回复微信机器人

发表回复

textsms
account_circle
email

DevsDawn

用itchat做一个简单的关键词回复微信机器人
itchat组件:https://github.com/littlecodersh/ItChat 下载后根据安装教程安装itchat pip install itchat 新建wxbot.py #coding=utf8 import itchat import time @itchat.msg_regist…
扫描二维码继续阅读
2017-06-25