猫史档案馆


【Python作品分享】自动聊天机器人【求助帖】

用户:我们都是追梦人YmxY我们都是追梦人YmxY查看:0 回复:1 评论:0 创建时间:2020-03-28T11:34:06


【作品展示】

center_image

 

【作品介绍】

要怎么运行

 

【作品源代码】

from wxpy import *
pip install - U wxpy - i "https://pypi.doubanio.com/simple/"
# 导入模块
# 初始化机器人,扫码登陆
bot = Bot()
# 搜索名称含有 "游否" 的男性深圳好友
my_friend = bot.friends().search('游否', sex=MALE, city="深圳")[0]
# 发送文本给好友
my_friend.send('Hello WeChat!')
# 发送图片
my_friend.send_image('my_picture.jpg')
# 打印来自其他好友、群聊和公众号的消息
@bot.register()
def print_others(msg):
    print(msg)

# 回复 my_friend 的消息 (优先匹配后注册的函数!)
@bot.register(my_friend)
def reply_my_friend(msg):
    return 'received: {} ({})'.format(msg.text, msg.type)

# 自动接受新的好友请求
@bot.register(msg_types=FRIENDS)
def auto_accept_friends(msg):
    # 接受好友请求
    new_friend = msg.card.accept()
    # 向新的好友发送消息
    new_friend.send('哈哈,我自动接受了你的好友请求')


# 进入 Python 命令行、让程序保持运行
embed()

# 或者仅仅堵塞线程
# bot.join()

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
星空之忆星空之忆

chatbot库

点赞0


评论