先放代码:
再放个文字的(方便复制):
import itchat
import requestsdef get_reply(keyword):try:url = f"https://open.drea.cc/bbsapi/chat/get?keyWord={keyword}&userName=type%3Dbbs"res = requests.get(url)data = res.json()return data['data']['reply']except:return "opps, 我还很笨,不造你在说啥"@itchat.msg_register(itchat.content.TEXT, isFriendChat=True)
def auto_reply(msg):reply = "execuse me?"try:reply = get_reply(msg.text)except:passfinally:print(f'[In] {msg.text} \t [Out] {reply}')return replyitchat.auto_login(hotReload=True)
itchat.run()
运行步骤:
控制台执行:
pip install itchat itchat-uos requests
执行保存上面代码到chatbot.py文件里,然后执行:
python chatbot.py
接着会弹出二维码,然后微信扫码,等待好友的消息,就可以开始尬聊~