Let's build Bots for STEEM - Part 05: Let's send messages to DISCORD using WEBHOOKS and WEBCORD
Hi Steemians, let's build BOTS!
On this blog I want to document my progress in implementing bots for the STEEM blockchain.
In my last post I developed a bot that sends messages to Discord. Unfortunately this bot breaks after some minutes due to a missing keep alive implementation.
In the last days I searched for a solution, until I detected the WEBHOOKS feature of Discord.
The Webhook
If you are admin of a Discord Server, you can create a so called WEBHOOK. A Webhook is an REST API endpoint that allows clients to send messages to Discord channels.
To create a new Webhook, open the Server-Settings, and select the WebHooks menu item.
Click the Create Webhook button and define the Name of the Webhook.
Please also copy&paste the WEBHOOK URL, we will need this URL later.
Install Webcord for Python
If we want to use the new WEBHOOK, we need an additional Python library. I decided to use webcord, but there are a lot of others available. To install webcord just type.
pip3 install webcord
Hello Discord
Now it's time to test our WEBHOOK. This tiny script sends a "Hello Discord" to our Discord channel.
from webcord import Webhook
webhook = Webhook("https://discordapp.com/api/webhooks/INSERT_WEBHOOK_URL_HERE", avatar_url=None)
webhook.send_message("Hello Discord", 'botsultant')
We only need to import Webhook from webcord. Please note that you need to insert your WEBHOOK-URL when calling the Webhook constructor.
If we run the script, we get
What's next?
In my next post we will add some more functionality to the script. I want to get all new posts with hashtag "utopian-io" in my own channel.