From 3948ae6d521e73954529563eb7526f7419e4b9c1 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Thu, 31 Aug 2023 06:20:16 +0800 Subject: tmp --- main.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 main.py (limited to 'main.py') diff --git a/main.py b/main.py new file mode 100644 index 0000000..8851a4c --- /dev/null +++ b/main.py @@ -0,0 +1,37 @@ +from requests import get +from time import sleep + +# Set up the necessary variables +token = 'MTE0MDk5MjQ2NjU2MTAwNzYxNw.GRZ07p.dwkI7bttQzfqr17OHFw2p0eCYtIplJrJF0P1oo' +user_id = ['898077475723161621', '912011643947479081'] +channel_id = '1140999625680101396' + +# 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 = "" + +def main(): + global old_message + # Make the API request to fetch messages from the channel + response = get(url, headers=headers) + + # Check if the request was successful (status code 200) + if response.status_code == 200: + messages = response.json() + # Process the user's messages + message = [message for message in messages if message['author']['id'] in user_id][0]['content'] + if message != old_message: + return message + old_message = message + else: + sleep(1) + else: + return f'Error: {response.status_code} - {response.text}' + +if __name__ == "__main__": + while 1: + print(main()) -- cgit v1.2.3