From 1fddde0b97a4abf2d649a951f5ffb3a8defbf5a2 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Wed, 16 Aug 2023 20:01:46 +0800 Subject: update --- index.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 index.py (limited to 'index.py') diff --git a/index.py b/index.py new file mode 100644 index 0000000..d8ca43b --- /dev/null +++ b/index.py @@ -0,0 +1,41 @@ +from flask import Flask, request +import requests + +app = Flask(__name__) + +# Set up the necessary variables +token = 'MTE0MTM0MDA2Mzk2ODU0MjczMA.G7bTuQ.kXvBg1R2N-3Z2cYUXDmEVcBIzc7Z_MWvP2Wjtg' +channel_id = '1140989222556274721' + +# Set the API endpoint +url = f'https://discord.com/api/v9/channels/{channel_id}/messages' + +# Set the headers with the bot token for authentication +headers = {'Authorization': f'Bot {token}'} + +old_message = "" + +@app.route('/', methods=['POST']) +def handle_post_request(): + global old_message + message = request.get_data().decode('utf-8') + + # Check if the message is different from the previous one + if message != old_message: + payload = { + 'content': message + } + + # Send the message to the Discord channel + response = requests.post(url, headers=headers, json=payload) + + if response.status_code == 200: + old_message = message + return 'Message sent to Discord channel successfully.' + else: + return f'Error sending message to Discord channel: {response.status_code} - {response.text}' + else: + return 'Duplicate message. Not sending to Discord channel.' + +if __name__ == '__main__': + app.run() -- cgit v1.2.3