I have a small discord bot and a small flask project (bot.py and app.py).
On my flask project I have an endpoint that I can receive JSON POST request (i can see the JSON fine). Now the question is how do I send from Flask to my Bot.py this JSON payload so that my bot.py posts it on my Discord channel.
My code:
- flask app:
from flask import Flask, json, request,
app = Flask(__name__)
@app.route('/', methods=['GET'])
def index():
return 'working ...'
@app.route('/webhook', methods=['POST'])
def jiraJSON():
if request.is_json:
data = request.get_json()
print(data)
return 'json received', 200
else:
return 'Failed - Not a JSON', 400
if __name__ == '__main__':
app.run()
- my bot.py from (https://realpython.com/how-to-make-a-discord-bot-python/)
# bot.py
import os
import discord
from dotenv import load_dotenv
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
client = discord.Client()
@client.event
async def on_ready():
print(f'{client.user} has connected to Discord!')
client.run(TOKEN)