summaryrefslogtreecommitdiff
path: root/index.py
blob: 963310b9e17537feb3172c435c0b1b5c7c0e2cf6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from flask import Flask, request
import requests

app = Flask(__name__)

# Set up the necessary variables
token = "OTEyMDExNjQzOTQ3NDc5MDgx.G_0FA6.4NubZfVPRUAiyVEaJiK39i78NCS-nH8RRKYcP4"
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()