How to send whatsApp message using pywhatkit in Python

Now, we will see how to send whatsApp message through website web.whatsapp.com using pywhatkit in Python that can automatically send messages to any WhatsApp number.

Send WhatApp message using pywhatkit in Python

Make sure that pywhatkit is installed in your environment.

To send whatsapp message using pywhatkit, we need a browser and in that browser, user needs to be logged into the website web.whatsapp.com

Syntax:

pywhatkit.sendwhatmsg(“Receiver number”,”Message”,Hours,Minutes)

Receiver number: It is the contact number that you want to send the message. The number should be in string format and country code should be present before the mobile number

Message: Message that needs to be sent for that contact

Hours: It should be in 24 hours time format

Minutes: It should be in range of 00-59

Hours and Minutes are the scheduled time that the message needs to be sent

Let’s see the code

#import the module
import pywhatkit

#using try and catch for avoiding errors
try:
    #sending the message to specific number
    pywhatkit.sendwhatmsg("+91xxxxxxxxxx","Hello",14,30)
    print("success")

except:
    #Handling exception
    print("An error occured")


  1. We have mentioned the phone number to be sent, then the message to be sent, and then the time to be sent. Here we pass 24 hrs time format, so the time 14:30 is 02:30 PM.
  2. We should pass the time minimum 2-3 minutes from the current time but if you keep 1-2 minutes from the current time, then an error will show up.
  3. Make sure that WhatsApp web is logged in the browser before running the program. For login open WhatsApp link and scan the given QR Code.

Output:

When the program runs successfully, it shows how much time WhatsApp will take to open and after how many seconds the message will be delivered. After that time, it will send the message to the respected number WhatsApp.

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

Also read:

One response to “How to send whatsApp message using pywhatkit in Python”

  1. kalebu Gwalugano says:

    Great one, I also recently made a python library that abstracts selenium and provides an easy and intuitive interface plus advanced control over the WhatsApp Web

Leave a Reply

Your email address will not be published.