Linux Automation Tip: Listen for Commands with your Discord Bot using Python
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:
https://makerhacks.com/python-messages-discord/
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
Running the Bot
First, you need to create your bott app, and associate a new bot with it:
Set up your App at the Discord Developer Site
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
When your script is running and the bot is authorized you should get notified in your server thusly:
Posted from my blog with SteemPress : https://makerhacks.com/python-discord-listener/
It would be helpful if I can see typical "prompt and response examples". Thanks for the tutorial
My next article on the subject will show my exact use of it, as you can see above this was just enough to do "hello world" type test :)
Can't wait to see it. I am soo following this!!
https://steemit.com/making/@makerhacks/linuxautomationtipprocessdiscordmessagesandlaunchshellcommandsinpython-951u969wqs