python笔记之微信机器人

版权声明:from 瑾川(fakehydra.xyz) https://blog.csdn.net/fake_hydra/article/details/84023121
# 初始化登陆信息
# 导入微信机器人包
import wxpy
# 完成二维码登陆,cache_path:建立wxpy.pkl缓存文件
wxpy.Bot(cache_path=True)
# 保持微信运行状态
wxpy.embed()

bot对象

# 将wxpy中所有变量导入
from wxpy import *
bot = Bot(cache_path=True)
# 返回值为登陆该账户的用户
print(bot)

# 获取所有好友
friends = bot.friends()
# print(friends)

# 自己
_self = friends[0]
print(_self)
# 性别
print(_self.sex)
# 省份
# print(_self.province)

# 所有分组
groups = bot.groups()
# print(groups)

# 指定分组
# 指定好友,指定分组都不能排除重名情况,所以search的结果为list类型
# 通常只有指定的一个好友|分组,那么就是list的第0位
groups = bot.groups().search("嘿嘿群")
print(groups)

embed()

指定好友回复

from wxpy import *
bot = Bot(cache_path=True)
friend = bot.friends().search("予你")


@bot.register()
def abs(msg):
    name = msg.sender.name
    print(msg.text)
    print(name + ":" + msg.text)
    if name == friend.name:
        return "自动回复,工作中勿扰"


embed()

猜你喜欢

转载自blog.csdn.net/fake_hydra/article/details/84023121