Let's build Bots for STEEM - Part 05: Let's send messages to DISCORD using WEBHOOKS and WEBCORD

in #steem7 years ago

Hi Steemians, let's build BOTS!

On this blog I want to document my progress in implementing bots for the STEEM blockchain.


Image Source: https://pixabay.com/de/roboter-computer-bots-charakter-764951/

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.

Coin Marketplace

STEEM 0.17
TRX 0.15
JST 0.028
BTC 58044.48
ETH 2352.63
USDT 1.00
SBD 2.36