create account

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

View this thread on: hive.blogpeakd.comecency.com
· @botsultant ·
$27.19
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. 

https://steemitimages.com/DQmYBEXnPDCks41VWPfQr5HAfE6kfMoH6NYArDbrkzND7pT/robots-764951_1280.png
<center>Image Source: https://pixabay.com/de/roboter-computer-bots-charakter-764951/</center>

In [my last post](https://steemit.com/steem/@botsultant/let-s-build-bots-for-steem-part-04-a-first-bot-for-discord) 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. 

https://steemitimages.com/DQmWXCzRiFS1dEGUkFX3TdMECVUdWKtS8qhc8F4vvFtqGJ5/Webhook1.png

Click the **Create Webhook** button and define the Name of the Webhook. 

https://steemitimages.com/DQmPwGpYE4kKGkLVH15USJgDq516wNA7wxEKEnLXhxZ5wsQ/Webhook2.png

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](https://github.com/maximinijanijos/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 

https://steemitimages.com/DQmbDYjFai6wQEZgXYQ7UnNwXYDKtMSGxCD1SZJqTH8oJqh/Webhook3.png

## 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.
👍  ,
properties (23)
authorbotsultant
permlinklet-s-build-bots-for-steem-part-05-let-s-send-messages-to-discord-using-webhooks-and-webcord
categorysteem
json_metadata{"tags":["steem","steemdev","utopian-io","python","discord"],"image":["https://steemitimages.com/DQmYBEXnPDCks41VWPfQr5HAfE6kfMoH6NYArDbrkzND7pT/robots-764951_1280.png","https://steemitimages.com/DQmWXCzRiFS1dEGUkFX3TdMECVUdWKtS8qhc8F4vvFtqGJ5/Webhook1.png","https://steemitimages.com/DQmPwGpYE4kKGkLVH15USJgDq516wNA7wxEKEnLXhxZ5wsQ/Webhook2.png","https://steemitimages.com/DQmbDYjFai6wQEZgXYQ7UnNwXYDKtMSGxCD1SZJqTH8oJqh/Webhook3.png"],"links":["https://pixabay.com/de/roboter-computer-bots-charakter-764951/","https://steemit.com/steem/@botsultant/let-s-build-bots-for-steem-part-04-a-first-bot-for-discord","https://github.com/maximinijanijos/webcord"],"app":"steemit/0.1","format":"markdown"}
created2018-01-17 09:48:12
last_update2018-01-17 09:48:12
depth0
children0
last_payout2018-01-24 09:48:12
cashout_time1969-12-31 23:59:59
total_payout_value20.524 HBD
curator_payout_value6.668 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length2,297
author_reputation113,201,096,904
root_title"Let's build Bots for STEEM - Part 05: Let's send messages to DISCORD using WEBHOOKS and WEBCORD"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id30,136,083
net_rshares3,184,166,898,020
author_curate_reward""
vote details (2)