##7行python代码实现微信聊天自动回复
需要安装wxpy模块
安装方法:pip install wxpy
根据需要可自己注册图灵机器人,获取api_key
下面的代码可以直接使用。
可以将程序代码打包成exe(pyinstaller 文件名.py -F)存放在电脑中,方便使用。
#代码
from wxpy import *
bot = Bot(cache_path=True)
tuling = Tuling(api_key='4a0488cdce684468b95591a641f0971d')
@bot.register()
def auto_reply(msg):
tuling.do_reply(msg)
embed()
指定聊天对象
from wxpy import *
turing = Tuling(api_key='4a0488cdce684468b95591a641f0971d')
bot = Bot()
#只跟某一个好友聊天
nc=input("输入好友昵称:")
xianding = bot.friends().search(nc)
@bot.register(chats=xianding)
def communite(msg):
turing.do_reply(msg)
embed()
指定聊天群
from wxpy import *
turing = Tuling(api_key='你的apikey')
bot = Bot()
#只在某个群内聊天
xianding = bot.groups().search('群名称')
@bot.register(chats=xianding)
def communite(msg):
turing.do_reply(msg)
bot.join()