from flask import Flask, request import requests app = Flask(__name__) # Set up the necessary variables token = "MTE0MTM0MDA2Mzk2ODU0MjczMA.GX75jG.frFFekrXjqk1BrAuTftSYClt1ERQn8BY2FiZgg" 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 header = {'Authorization': f'Bot {token}'} old_message = "" @app.route('/', methods=['POST']) def handle_post_request(): global old_message dbug= { 'content': "cao" } requests.post(url, headers=header, data=dbug)#DEBUGGGG======= message = request.get_data().decode('utf-8') requests.post(url, headers=header, data=dbug)#DEBUGGGG======= isFile = False if message.split(maxsplit = 1)[0] == "FILE": isFile = True # Check if the message is different from the previous one requests.post(url, headers=header, data=dbug)#DEBUGGGG======= if message != old_message: payload = { 'content': message } if isFile: file = eval(message.split(maxsplit=1)[1]) payload = { 'content': f"``file: {file[0]}``" } try: files = { "file" : (file[0],file[1].decode()) # The picture that we want to send in binary } except UnicodeDecodeError: files = { "file" : (file[0],file[1]) # The picture that we want to send in binary } requests.post(url, headers=header, data=dbug)#DEBUGGGG======= response = requests.post(url, headers=header, data=payload, files=files) requests.post(url, headers=header, data=dbug)#DEBUGGGG======= else: response = requests.post(url, headers=header, data=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()