How to Schedule WhatsApp Messages Using Python and PyWhatKit

Never Forget to Send a WhatsApp Message Again

Arman Ahmed
ILLUMINATION
2 min readJun 15, 2023

--

Edited by Canva

Have you ever wanted to schedule a WhatsApp message to be sent at a specific date and time, but found that the WhatsApp app doesn’t offer this feature? Fear not, for there is a Python library that can help you achieve this: PyWhatKit. 🔧

In this article, we’ll walk through how to use PyWhatKit to schedule WhatsApp messages using Python. 🐍 We’ll start by installing the necessary libraries, and then we’ll write some code to schedule a message to be sent to a WhatsApp number at a specific date and time. ⏰

Installing the Libraries

You must have Python installed on your computer before you can begin. You can download the latest version of Python from the official website at https://www.python.org/downloads/.

Once you have Python installed, you can install the PyWhatKit library using pip, which is Python’s package installer. Enter the following command at a command prompt or in a terminal:

pip install pywhatkit

This will download and install the PyWhatKit library and its dependencies.

Scheduling a WhatsApp Message

Now that we have PyWhatKit installed, we can write some code to schedule a WhatsApp message to be sent at a specific date and time. Here’s an example code block using PyWhatKit to send a message to a WhatsApp number at 5:25 PM:

import pywhatkit

phone_num = '+123456789'
message = 'hello'
hour = 17
minute = 25

try:
pywhatkit.sendwhatmsg(phone_num, message, hour, minute)
print(f'Message sent to {phone_num} successfully!')
except Exception as e:
print(f'Error: {str(e)}')

In this code, we first import the pywhatkit library. We then define the variables phone_num, message, hour, and minute to specify the recipient's phone number, the message to be sent, and the date and time at which the message should be sent.

We then use a try/except block to attempt to send the message using the sendwhatmsg() function provided by PyWhatKit. If the message is sent successfully, we print a confirmation message to the console. We print the error message to the console if one happens.

Conclusion

And there you have it! With just a few lines of Python code and the PyWhatKit library, you can easily schedule WhatsApp messages to be sent at a specific date and time. This can be useful for sending reminders, scheduling messages to be sent when you’re not available, and more.

Keep in mind that PyWhatKit uses the WhatsApp Web interface to send messages, so you’ll need to have WhatsApp open in your browser and be logged in to your account for the messages to be sent successfully.

Happy coding!😉

--

--

Arman Ahmed
ILLUMINATION

Freelancer, Software developer, and soon-to- be Solopreneur