Open In App

Automate WhatsApp Messages With Python using Pywhatkit module

We can automate a Python script to send WhatsApp messages. In this article, we will learn the easiest ways using pywhatkit module that the website web.whatsapp.com uses to automate the sending of messages to any WhatsApp number.

Installing pywhatkit module:

pywhatkit is a python module for sending Whatsapp messages at a certain time. To install the pywhatkit module, Type the following command in your IDE/Compiler:



pip install pywhatkit

This command will download the pywhatkit module. It will cause some delay as it will download some related modules too.

Using pywhatkit module:

To use this python library to send messages automatically on WhatsApp at certain times, we need a chrome browser and you must have your WhatsApp logged into the web.whatsapp.com website.



If you do not have a chrome browser, then you can follow the following steps:

Below is the implementation:




import pywhatkit
 
 
pywhatkit.sendwhatmsg("+919xxxxxxxxx",
                      "Geeks For Geeks!",
                      18, 30)

Output:

Explanation:

Now just run the final script to send a WhatsApp message. After running the script, It will let you know that after how many seconds your WhatsApp going to open and what particular time your message would be sent. After that many seconds, this script will automatically open WhatsApp and it will send the message to the specified recipient.

For example, 

In 51 seconds web.whatsapp.com will open and after 20 seconds message will be delivered

Some Error Messages You May Encounter during Execution:

1. While installing the Pywhatkit module, you may encounter this error message:

“The headers or library files could not be found for zlib, a required dependency when compiling Pillow from source.”

Solution: Upgrade pip and pillow. Run the codes below separately:

2. Specify the minutes’ argument by starting with 0. For instance 6:08 PM as 18, 08. You will get a syntax error:

“SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers.”

Solution: Start your minutes’ argument with a number other than 0.

3. If the recipient phone number you want to send a message to doesn’t have a country code. You will get this error:

“CountryCodeException(“Country code missing from phone no”)”

“pywhatkit.mainfunctions.CountryCodeException: Country code missing from phone no”

Solution:  Include the country code for every phone number. For example, +234, +44, +1.

4. When you have slow internet, your message will not be sent. You will get this error message:

“raise Warning(“INTERNET IS SLOW, extraction of information might take longer time”)”

“Warning: INTERNET IS SLOW, extraction of information might take longer time”

Solution:  Use a strong internet connection.

Article Tags :