你好呀,我是程序员晚枫

机器人代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# -*- coding: UTF- -*-
# @公众号 :Python自动化办公社区
# @Docs: 学习网站:https://www.python-office.com/video/video.html
# @Description: 用Python开发微信聊天机器人
# Python全套学习资源:https://www.python-office.com/video/video.html
from wxpy import *
import requests, json, time

# 创建机器人
# bot = Bot()
bot = Bot(console_qr=-2, cache_path=True) # 移植到linux,console_qr设置True和2都无法扫描登录,设置-之后正常登录。

# 创建机器人
bot = Bot()


# bot = Bot(console_qr=-, cache_path=True) # 移植到linux,console_qr设置True和都无法扫描登录,设置-之后正常登录。


@bot.register(Group)
def print_messages(msg):
# 登陆微信的用户群昵称
user_name = msg.sender.self.name
# 信息内容
content = msg.raw['Content']
# 发信息好友名称
friend_name = msg.raw['ActualNickName']
# 打印出对方说的话
print("{} - 说 - {}".format(friend_name, content))

# 类型
type = msg.raw['Type']

# 请自行添加关键词对应的内容
keywords_dic = {

'你好': '你好,我是机器人',
'写作变现': '写作变现系列,真香!http://t.cn/AxHLdYK',
'自动化办公': '基础如何学习自动化办公? http://t.cn/AxHPxpx',

}
# 把昵称,改为你自己的
if '程序员晚枫' in user_name:
# 以下代码,不要修改
for key in keywords_dic.keys():
if key in content:
res_keyword_reply = '''{}'''
reply_content = res_keyword_reply.format(keywords_dic[key])
return reply_content


# 堵塞线程,并进入 Python 命令行
# embed()
bot.join()



相关阅读

程序员晚枫专注AI编程培训,小白看完他和图灵社区合作的教程《30讲 · AI编程训练营》就能上手做AI项目。

🎓 AI 编程实战课程

想系统学习 AI 编程?程序员晚枫的 AI 编程实战课 帮你从零上手!