1. 程式人生 > >用python6行程式碼實現微信機器人

用python6行程式碼實現微信機器人



# 初始化機器人,掃碼登陸
bot = Bot()

# 搜尋名稱含有 "遊否" 的男性深圳好友
my_friend = bot.friends().search('遊否', sex=MALE, city="深圳")[0]

# 傳送文字給好友
my_friend.send('Hello WeChat!')
# 傳送圖片
my_friend.send_image('my_picture.jpg')

xiaoi = XiaoI('your key', 'your secret')

# 使用小 i 機器人自動與指定好友聊天
@bot.register(my_friend)
def reply_my_friend(msg):
    xiaoi.do_reply(msg)
    
#使用小 i 機器人自動hyu好友、與群友聊天
@bot.register(msg_types=TEXT)
def reply_my_friend(msg):
    xiaoi.do_reply(msg)
    empty