summaryrefslogtreecommitdiff
path: root/index.py
diff options
context:
space:
mode:
authorlittleblack111 <jerrylam110209@gmail.com>2023-08-16 20:01:46 +0800
committerlittleblack111 <jerrylam110209@gmail.com>2023-08-30 21:23:34 +0800
commit1fddde0b97a4abf2d649a951f5ffb3a8defbf5a2 (patch)
treeb58347ba00cb09dde2091d3346cfcbc63f199390 /index.py
parent09eb3748453b06f10ce1d6b664698ff602a52637 (diff)
update
Diffstat (limited to 'index.py')
-rw-r--r--index.py41
1 files changed, 41 insertions, 0 deletions
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()