Integrate Discord with your Bevy Community using Webhooks.
In this post, you'll find the steps to automate a notification in a Discord Channel every time a new event is published in Bevy.
I used a test environment, using Python and Flask to create my script, but the integration can be done using any other programming language or tools.
Step 1: Create a Discord Webhook
1. Open Discord and go to the server where you want to send notifications.
2. Navigate to the channel settings by clicking the gear icon next to the channel name.
3. Go to the Integrations tab and click on Webhooks.
4. Click on New Webhook.
5. Name your webhook, select the channel where it will post, and click Copy Webhook URL.
6. Save this URL as you will need it later.
Step 2: Create the script that Triggers the Discord Webhooks
In this example, we will use Flask with Python.
1. Install the following libraries:
pip install requests
pip install flask
2. Create your 'app.py' script:
from flask import Flask, request, jsonify
import requests
import json
app = Flask(__name__)
# Discord webhook URL
discord_webhook_url = "[ADD HERE YOUR DISCORD WEBHOOK URL]"
@app.route('/webhook', methods=['POST'])
def webhook():
if request.json is None:
return jsonify({"error": "No JSON data received"}), 400
# Get event data from the request
events = request.json
for event_dict in events:
if 'data' in event_dict and isinstance(event_dict['data'], list):
for event in event_dict['data']:
event_title = event.get('title', 'No title')
event_start_date = event.get('start_date', 'No start date')
event_url = event.get('url', 'No URL')
# Construct message
message = f"New event published!\nTitle: {event_title}\nStart Date: {event_start_date}\nURL: {event_url}"
# Send message to Discord webhook
discord_payload = {
"content": message
}
response = requests.post(discord_webhook_url, json=discord_payload)
if response.status_code != 204:
return jsonify({"error": f"Failed to send message for event: {event_title}"}), 500
return jsonify({"message": "Messages sent successfully"}), 200
if __name__ == '__main__':
app.run(port=5000)
3. Remember to add your Discord Webhook URL to the script.
Step 3: Configure your Bevy Webhooks
1. In the Admin dashboard, click Settings in the left-hand sidebar menu.
2. On the General tab, go to the Webhooks section.
3. Complete the Webhook URL, Webhooks Secret Key, and Webhooks Secret fields.
4. Check the "Send event updates" checkbox. This enables the triggering of the Webhook notification when a new event is published, edited, or canceled.
For more information about Bevy Webhooks configuration, take a look at this article.
Step 4: Test the Integration
You can test the program by sending a POST API to your webhook URL. Note that you'd need to include a payload similar to:
[{
"data":[{
"title":"Community Event",
"start_date":"2024-05-30T09:30:00+02:00",
"url":"https://my-community-site.com/events/details/community-event"
}]
}]
Here you can see the message we triggered with this example script:
Your Bevy Events should now be announced in Discord!
Comments