How To Create Whatsapp Bot Using
Pywhatkit
#2 Python Weekly
Sophia Iroegbu · Sep 30, 2021 · 3 min read
PLAY THIS ARTICLE
4
SPEED
0:00 / 2:37
1X
Hello there!
Today on Python weekly, We will be creating Whatsapp bot using pywhatkit.
A Little About PyWhatKit
Before we start, let me tell you about pywhatkit.
PyWhatKit is a Python library with various helpful features. It is an easy-to-use
library that does not require you to do some additional setup. It can be used to:
Send WhatsApp messages.
Play a YouTube video.
Perform a Google Search.
Get information on a particular topic.
Converting text into handwritten text images.
Now that is you know what pywhatkit is.
Let's start coding 🚀
Create and Activate your virtual environment.
Never forget to create and activate your virtual environment.
Why? Virtual environments create an isolated environment for Python projects.
Install PyWhatKit
This library can be installed by the pip command, open your command prompt,
and type in the following command.
COPY
pip3 install pywhatkit
Create a .py file and start calling the functions
First, import the library using the command import pywhatkit and then proceed
to call the functions
COPY
import pywhatkit
Add DateTime module
The DateTime module supplies classes for manipulating dates and times. This is
a python package so no need to install it.
COPY
import pywhatkit
from DateTime import datetime
Your code should look like this.
A date in Python is not a data type of its own, but we can import a module
named DateTime to work with dates as date objects.
COPY
today = [Link]()
This displays the current date and time
Convert DateTime object to an equivalent string
COPY
shour = [Link]("%H")
In the above program, %H is a format code. The strftime() method takes the
format code as an argument and returns a formatted string based on it.
%H: Is a format code for hour (24-hour clock) as a decimal number.
Add information to message a Whatsapp number
COPY
mobile_no = input('Enter Mobile Number of Receiver: ')
message = input('Enter Message you want to send : ')
Add Minute and Hour you want to send your message
COPY
hour = int(input('Enter hour : '))
minute = int(input('Enter minute : '))
Finally, send the message
COPY
[Link](mobile_no,message,hour,minute)
This function can be used to send WhatsApp messages at a certain time.
.sendwhatmsg_instantly() can be used to send message instantly.
While kit.sendwhatmsg_to_group() can be used to send messages to a group.
Your code should look like this
COPY
import pywhatkit
from datetime import datetime
today = [Link]()
shour = [Link]("%H")
mobile_no = input('Enter Mobile Number of Receiver: ')
message = input('Enter Message you want to send : ')
hour = int(input('Enter hour : '))
minute = int(input('Enter minute : '))
[Link](mobile_no,message,hour,minute)
That's it, guys. You've just created your first Whatsapp bot using pywhatkit. I
know it's a funny name 😂
The project is on Github here is the link:
[Link]/Sophyia7/[Link], if you have any issues let me know.
Let's Connect
Thanks for staying till the end ❤️. Let's connect via
Email - iroegbusophia3@[Link]
Discord - Sophyia#8929
Subscribe to my newsletter
Read articles from Tekie's Corner directly inside
your inbox. Subscribe to the newsletter, and
don't miss out.
Follow
Tekie s Corner oo
Enter your email address SUBSCRIBE
2Articles1Week Python Tutorial python projects Hashnode
Written by
Sophia Iroegbu Follow
Hello, I am a developer from Nigeria. I enjoy creating bespoke websites
and creating databases. Besides programming, I enjoy writing. I write
copies and articles. Some days, stories or poem.
ARTICLE SERIES
Python Weekly
Creating Your First Django Http Response
Apiviews
1 Hello There! 🌈 Today on Python Weekly, we would
be creating a REST API using Django for a book E-st…
How To Create Whatsapp Bot Using Pywhatkit
2 Hello there! Today on Python weekly, We will be
creating Whatsapp bot using pywhatkit. A Little Ab…
Turn Your Pdf Into An Audiobook Using Python
3 Hello there! 👋 In this article, I will teach you how to
turn your PDF note into an audiobook with j…
The Easist Way To Create Your Secret Key In
Three Simple Steps
4 Hello there! 👋 In this article, you will be learning how
to generate your secret key for your pytho…
How To Create A Custom Token Auth Using
Python
5 Hello there 👋, Today I am going to talk about a
recent feature I struggled to implement on Django …
©2024 Tekie's Corner
Archive · Privacy policy · Terms
Publish with Hashnode
Powered by Hashnode - Home for tech writers and readers