微信群转播机器人python练习制作

import itchat
import time
import datetime
from itchat.content import *
itchat.auto_login(True)
#设置关键群
#u'测试1'  为需要接收信息群
#u'测试2'  为需要转发信息群
#u'金叶'  为需要转发此人信息
a = itchat.search_chatrooms(name=u'测试1')[0]['UserName']
b = itchat.search_chatrooms(name=u'测试2')[0]['UserName']
c = itchat.search_chatrooms(name=u'测试3')[0]['UserName']
e = itchat.search_friends(name=u'金叶')[0]['UserName']
#打印登陆者微信名字
print(itchat.search_friends()['NickName'])
#微信收到消息触发本事件
@itchat.msg_register(TEXT, isGroupChat=True)
def text_reply(msg):
    #先判断消息来源是否来自需要转发的群(无特定来源可删除此if)
    if msg['FromUserName'] == b:
        #判断消息来源是否来自需要转发的人(无特定来源可删除此if)
        if msg['ActualUserName'] == e:
            #转发
            
            itchat.send(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())) + msg['ActualNickName'] +':'+ msg['Content'], c)
itchat.run()

练习时只需要下载itchat模块就可以了 , 测试的时候需要将群保存至测试号的通讯簿里才可以使用 , 要不然会出错 , 想自己添加验证信息也可以。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值