• Skip to main content
  • Skip to header right navigation
  • Skip to site footer
  • YouTube
  • MakerWorld
  • Instagram
  • Threads
  • Bluesky
  • Mastodon
  • Facebook
makerhacks-logo

Maker Hacks

Ideas, news & tutorials for makers and hackers – Arduino/Raspberry Pi, 3D printing, robotics, laser cutting, and more

  • Home
  • About
  • 3D Printing
  • Laser Cutting
  • CNC
  • Programming
  • Free Arduino Course
  • Free Robotics Course
  • Recommendations

Linux Automation Tip: Send Messages to Your Discord Server Using Python

You are here: Home / Software and Programming / Linux Automation Tip: Send Messages to Your Discord Server Using Python
Author: Chris Garrett
ping discord with python

I am on a mission to declutter my email. Once you get past the unsubscribe/filter stage, the next thing is to get the important information in a different way. Once I started down this path, however, I discovered this approach allows me to have fewer tabs open, and even concentrate more.

What is this magic? Ping your own Discord server … wait! Let me explain!

Before we start, the tool I am using to unsubscribe from the cruft that clogs my inbox is called Unroll.me – check it out.

Now, Discord.

Discord is a live chat system – but not JUST that

Most people know Discord from gaming. It’s a chat system like Slack or Hipchat, but more informal and less business focused. The best part is the free service is full of neat features.

While joining chats might seem counter to the goal of productivity and calm, you don’t have to chat with anyone.

Hence me using Discord instead of Slack. My work is full of Slack conversations and sometimes I need to close Slack and get some writing or code produced (often on a deadline). I can’t use Slack to keep me informed if that is going to draw me into conversations.

My Discord server, however, can be live without anyone knowing and can work across all my devices.

Sign up here to get started.

Pinging your server with Python

There is a fully featured API, but the easy start is with Webhooks – simple URLs that you pass your message to. When you ping these URLs your payload gets passed to your Discord channel.

Be aware these Webhooks can send messages from anyone if they get into the wrong hands, treat it a bit like a password.

Grab your webhook using this guide.

Code

# system library for getting the command line argument
import sys

# web library
import http.client

def send( message ):

    # your webhook URL
    webhookurl = "https://discordapp.com/api/webhooks/YOURWEBHOOK"

    # compile the form data (BOUNDARY can be anything)
    formdata = "------:::BOUNDARY:::\r\nContent-Disposition: form-data; name=\"content\"\r\n\r\n" + message + "\r\n------:::BOUNDARY:::--"

    # get the connection and make the request
    connection = http.client.HTTPSConnection("discordapp.com")
    connection.request("POST", webhookurl, formdata, {
        'content-type': "multipart/form-data; boundary=----:::BOUNDARY:::",
        'cache-control': "no-cache",
        })

    # get the response
    response = connection.getresponse()
    result = response.read()

    # return back to the calling function with the result
    return result.decode("utf-8")

# send the messsage and print the response
print( send( sys.argv[1] ) )

To test this example script out, simply call the .py with your message as the first parameter:


Now anything that might otherwise have gone to my inbox (eg. my dev machine IP address) can instead just go into the channel, and I can see my alerts in the usual way, or check in later with selective muting.

Category: Software and ProgrammingTag: automation, discord, Hacks, linux, python

About Chris Garrett

Marketing nerd by day, maker, retro gaming, tabletop war/roleplaying nerd by night. Co-author of the Problogger Book with Darren Rowse. Husband, Dad, 🇨🇦 Canadian.

Check out Retro Game Coders for retro gaming/computing.

☕️ Support Chris on Ko-Fi to get exclusive content and rewards!

Previous Post:Cryptocurrency Mining RigBuilding a Cryptocurrency Mining Rig is Easier than You Might Think
Next Post:Creality CR-10 MINI ReviewCreality CR-10 MINI

Sidebar

  • Facebook
  • Instagram
  • YouTube

Featured Posts

  • CyberBrick Review + Getting Started
  • xTool M2 Review
  • xTool F2 Ultra Review
  • xTool F2 Review
  • xTool S1 Review
  • Anycubic Kobra S1 Combo Review
  • Makera Z1 Pro Review
  • CNC Buyer's Guide
  • eufyMake E1 UV Printer Review
  • eufyMake Purifier P1
  • Z80 on a Breadboard
  • OpenSCAD MakerWorld Customizer

30 Days to Arduino

Arduino Tutorials
  • 3D Printing
  • CNC
  • Electronics and Hardware
  • Laser Cutting
  • News and Reviews
  • Software and Programming

arduino budget cad cnc diode laser glowforge Hacks Ideas laser cutter linux Makes making python raspberry pi Reviews technology tips xtool xTool Lasers

  • YouTube
  • MakerWorld
  • Instagram
  • Threads
  • Bluesky
  • Mastodon
  • Facebook

.

Maker Hacks Blog Copyright © 2026 · All Rights Reserved · Privacy Policy