失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > Python项目:实现微信聊天机器人

Python项目:实现微信聊天机器人

时间:2022-11-04 02:18:27

相关推荐

Python项目:实现微信聊天机器人

说明,以下内容有很多个版本,都可以使用。自己根据日期分割来看看

'''

from wxpy import *from chatterbot import ChatBotfrom chatterbot.trainers import ChatterBotCorpusTrainerchatbot = ChatBot("deepThought")# 用于回复消息的机器人chatbot.set_trainer(ChatterBotCorpusTrainer)chatbot.train("chatterbot.corpus.chinese")# 使用该库的中文语料库bot = Bot(cache_path=True)# 用于接入微信的机器人group_2 = bot.groups()[0]# 进行测试的群group_2.send("大家好,我是机器人Jack")@bot.register(group_2)def reply_my_friend(msg):print(msg)return chatbot.get_response(msg.text).text# 使用机器人进行自动回复# 堵塞线程,并进入 Python 命令行embed()#-01-28 17:54:15 January Sunday the 04 week, the 028 day SZ SSMRfrom wxpy import *# 实例化,并登录微信bot = Bot(cache_path=True)# 调用图灵机器人API,api_key需要在图灵机器人官网注册账号,然后就有了tuling = Tuling(api_key='a1bbc12dd78b4837b22cd8e98d96e027')# 查找到要使用机器人来聊天的好友groups1 = ensure_one(bot.search(u'小明深圳交流群','我是海归·吃货俱乐部2','原始森林.de','fancy','侯杏','DE Sprachstammtisch 1'))groups1.send("hello,我是逗比出气筒Jack,欢迎随时撩我")# 使用图灵机器人自动与指定好友聊天groups@bot.register(groups1)def auto_reply(msg):tuling.do_reply(msg)embed()#-01-27 15:44:14 January Saturday the 04 week, the 027 day SZ SSMR#与所有人聊天,并且不用二维码,直接在手机登陆网页版微信就行from wxpy import *apikey = 'a1bbc12dd78b4837b22cd8e98d96e027'#微信登录robot = Robot()#信息注册@robot.register()def Reply(msg):reply = Tuling(api_key=api_key).reply_text(msg,to_member=True)return reply#监听robot.start()#-01-28 18:26:31 January Sunday the 04 week, the 028 day SZ SSMR#-01-27 16:48:33 January Saturday the 04 week, the 027 day SZ SSMR#与所有人聊天,并且不用二维码,直接在手机登陆网页版微信就行from wxpy import *# 实例化,并登录微信bot = Bot(cache_path=True)# 调用图灵机器人APItuling = Tuling(api_key='a1bbc12dd78b4837b22cd8e98d96e027')@bot.register()def auto_reply(msg):tuling.do_reply(msg)embed()'''#-01-27 15:42:22 January Saturday the 04 week, the 027 day SZ SSMR#只能和特定微信群聊天from wxpy import *from chatterbot import ChatBotfrom chatterbot.trainers import ChatterBotCorpusTrainerchatbot = ChatBot("deepThought")# 用于回复消息的机器人chatbot.set_trainer(ChatterBotCorpusTrainer)chatbot.train("chatterbot.corpus.chinese")# 使用该库的中文语料库bot = Bot(cache_path=True)# 用于接入微信的机器人#group_2 = bot.groups()[0]# 进行测试的群#group_2.send("大家好,我是机器人Jack")@bot.register()def reply_my_friend(msg):print(msg)return chatbot.get_response(msg.text).text# 使用机器人进行自动回复# 堵塞线程,并进入 Python 命令行embed()'''#-01-28 19:04:29 January Sunday the 04 week, the 028 day SZ SSMRfrom wxpy import *from chatterbot import ChatBotfrom chatterbot.trainers import ChatterBotCorpusTrainerchatbot = ChatBot("deepThought")# 用于回复消息的机器人chatbot.set_trainer(ChatterBotCorpusTrainer)chatbot.train("chatterbot.corpus.chinese")# 使用该库的中文语料库bot = Bot(cache_path=True)# 用于接入微信的机器人group_2 = bot.groups("友谊是")[0]# 进行测试的群group_2.send("hi")@bot.register(group_2)def reply_my_friend(msg):print(msg)return chatbot.get_response(msg.text).text# 使用机器人进行自动回复# 堵塞线程,并进入 Python 命令行embed()''''''#-01-27 15:38:18 January Saturday the 04 week, the 027 day SZ SSMR#robot = Robot()这行有问题,无法识别Robot()#-01-27 16:49:30 January Saturday the 04 week, the 027 day SZ SSMR#二维码在黑板里,无法扫描import itchatfrom chatterbot import ChatBotfrom chatterbot.trainers import ChatterBotCorpusTrainerdeepThought = ChatBot("deepThought")deepThought.set_trainer(ChatterBotCorpusTrainer)# 使用中文语料库训练它deepThought.train("chatterbot.corpus.chinese") @itchat.msg_register(itchat.content.TEXT)def text_reply(msg):response = deepThought.get_response(msg['Text'])print("from",msg['FromUserName'],msg['Text'])print("to",response)itchat.send(msg=str(response),toUserName=msg['FromUserName'])itchat.auto_login(enableCmdQR=True)itchat.run()'''

如果觉得《Python项目:实现微信聊天机器人》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。