Use Python to send a WhatsApp message to someone.

ยท

2 min read

Here's how you can send a WhatsApp message to someone using Python and the pywhatkit library:


Step-by-Step Guide

Step 1: Install the Required Library

First, install the pywhatkit library if you haven't already:

pip install pywhatkit

Step 2: Write the Python Script

Below is the Python script to send a WhatsApp message:

import pywhatkit as kit

# Parameters
phone_number = "+1234567890"  # Replace with recipient's phone number (with country code)
message = "Hello! This is a message sent using Python. ๐Ÿ"  # Your message
hour = 14  # Hour in 24-hour format
minute = 30  # Minute

try:
    # Schedule the message
    kit.sendwhatmsg(phone_number, message, hour, minute)
    print("Message successfully sent!")
except Exception as e:
    print(f"An error occurred: {e}")

How It Works

  1. kit.sendwhatmsg Parameters:

    • phone_number: The recipient's WhatsApp number (include the country code).

    • message: The text you want to send.

    • hour and minute: When to send the message.

  2. Execution:

    • The script will open WhatsApp Web in your default browser.

    • The message will be sent automatically at the specified time.

  3. Ensure:

    • Your system has a stable internet connection.

    • You're logged into WhatsApp Web on your browser.


Additional Features of pywhatkit

  • Send Messages to Groups:
    Use kit.sendwhatmsg_to_group("GroupID", "Message", Hour, Minute).

  • Instant Message Sending:
    Use kit.sendwhatmsg_instantly(phone_number, "Message").

  • Message with Media:
    Use kit.sendwhats_image(phone_number, "Path_to_Image", "Caption").


Output

The program will automatically open WhatsApp Web and send the message at the scheduled time.

Let me know if you encounter any issues or need further assistance! ๐Ÿš€

ย