Itchat send messages to the specified contact person

Source: Internet
Author: User
First install Itchat, you can see my other blog
Import Itchat
itchat.auto_login ()
itchat.send (' Hello, Filehelper ', tousername= ' Filehelper ')

This code means to send a hello,filehelper to Filehelper is the file assistant.

So we want to send a message to the designated person, not to get rid of filehelper so simple

Users=itchat.search_friends ("Lao Wang")
username= users[0][' userName ']
print (userName)
itchat.send (' Hello Old king ' , Tousername=username)

If we want to give old Kings news, we'll use the Itchat.search method first, and all the notes will be found by the old Wang's contact person.

Then we pick the first one (if you have only one old king in your contact list, you'll only find one).

USERS[0] Fetch is a contact object, he has a key called username, it is the real user's username

Then we use the Itchat.send method, we can successfully send the message to Lao Wang


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.