Hello, this is tmasuyama of cloud engineers.
Nowadays, online drinking parties are popular, but there are various tools. I feel that Discord is quite popular around me.
Of course, unlike Zoom, there is no time limit for 3 or more people. It's good that there is little delay and that some noise is automatically eliminated.
Although it is such Discord, you can skip notifications with Bot like Slack and LINE. You can use it like curl, so let's introduce how to use it.
Get the WebHookURL that corresponds to the API key. After creating the channel, jump to the setting screen from the gear mark.
When you open it, there is an item called ** Webhook **, so click it.
Select ** Create Webhook **.
The name field will be the bot name when notified by Discord. Also, make a copy of the ** Webhook URL ** as it will be used later in the Python file.
This completes the preparations.
No special preparation is required on the Python side, and the requests module is used. Here, let's notify you of the classic ** Hello, World! **.
discord_bot.py
# coding: utf-8
import requests
discord_webhook_url = 'Webhook URL you copied earlier'
data = {"content": "Hello, World!"}
requests.post(discord_webhook_url, data=data)
When you run it, you will be notified on the Discord channel in the following form.
You could skip the notification with just this code. Thank you for your hard work.
Recommended Posts