• Skip to main content
  • Skip to header right navigation
  • Skip to site footer
Maker Hacks

Maker Hacks

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

  • Home
  • About
  • YouTube
  • Recommendations
  • Contact

Linux Automation Tip: Listen for Commands with your Discord Bot using Python

You are here: Home / News, Events, Competitions, Prize Draws, and Launches / Linux Automation Tip: Listen for Commands with your Discord Bot using Python
FacebookTweetPin
Author: Chris Garrett

A Discord bot that only SENDS messages is all well and good, but really we want our bots to interact. We need to make them listen and respond.

Python Discord Bot
Python Discord Bot

A Discord bot that only SENDS messages is all well and good, but really we want our bots to interact. We need to make them listen and respond. Let’s do that now.

Previously:

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

Event Driven Computing

If you have done any visual or object-oriented programming you will be aware of what is called listening for or raising an “event”.

Essentially your program keeps quietly processing until something happens, then it jumps into action.

So with this in mind, we need to tell our bot what to look for and how to respond!

Code

You will need the Discord code library before you can run any of these commands so grab it like so:

python3 -m pip install discord

(Copy and paste the code from this Gist here)

Discord Bot Python Code
Discord Bot Python Code

Running the Bot

First, you need to create your bott app, and associate a new bot with it:

Discord - Developer Site
Set up your App at the Discord Developer Site

Discord - Developer Documentation-1

Then you need to go to the permissions URL to authorize your bot to do its thing:

https://discordapp.com/oauth2/authorize?&client_id=YOUR_CLIENT_ID&scope=bot&permissions=0

Authorize access to your account
Authorize access to your account

When your script is running and the bot is authorized you should get notified in your server thusly:

Related

Category: News, Events, Competitions, Prize Draws, and LaunchesTag: linux, making, programming, python, technology
FacebookTweetPin

About Chris Garrett

Marketing Director 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 Maker Hacks on Ko-Fi and get exclusive content and rewards!

Previous Post:Creality CR-10 MINICreality CR-10 MINI Review
Next Post:Linux Automation Tip: Process Discord Messages and Launch Shell Commands in Python

Sidebar

  • Facebook
  • Twitter
  • Instagram
  • YouTube

Recently Popular

  • Gweike Cloud Review
  • How to choose the right 3D printer for you
  • Glowforge Review – Glowforge Laser Engraver Impressions, Plus Glowforge Versus Leading Laser Cutters
  • Original Prusa i3 Mk3S Review
  • Best 3D Printing Facebook Groups
  • Elegoo Mars Review – Review of the Elegoo Mars MSLA Resin 3D Printer
  • Glowforge ‘Pass-Through’ Hack: Tricking the Front Flap of the Glowforge with Magnets to Increase Capacity
  • How to Make a DIY “Internet of Things” Thermometer with ESP8266/Arduino
  • Wanhao Duplicator i3 Review
  • IKEA 3D Printer Enclosure Hack for Wanhao Di3
  • Creality CR-10 3d printer review – Large format, quality output, at a low price!
  • 3D Printed Tardis with Arduino Lights and Sounds
  • Anet A8 Review – Budget ($200 or less!) 3D Printer Kit Review
  • Make your own PEI 3D printer bed and get every print to stick!
  • Upgrading the Wanhao Di3 from Good to Amazing
  • How to Install and Set Up Octopi / Octoprint
  • Creality CR-10 S5 Review

Copyright © 2023 · Maker Hacks · All Rights Reserved · Powered by Mai Theme