summaryrefslogtreecommitdiff
path: root/main.py.new.bak
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2023-09-01 07:24:33 +0800
committerlittleblack111 <littleblack11111@gmail.com>2023-09-01 07:24:33 +0800
commit0499276a086fce90bc1ed97b27f4e1b5d83ff12b (patch)
tree493232da23c7c6cbabe7995d5d9a8c05715f5337 /main.py.new.bak
parent3fb0b3984664fcabe34a91458355da2864404f14 (diff)
reverted before main for fixing future error
Diffstat (limited to 'main.py.new.bak')
-rw-r--r--main.py.new.bak87
1 files changed, 87 insertions, 0 deletions
diff --git a/main.py.new.bak b/main.py.new.bak
new file mode 100644
index 0000000..69f7e46
--- /dev/null
+++ b/main.py.new.bak
@@ -0,0 +1,87 @@
+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_id = ""
+def main():
+ global old_id
+ global url
+ # 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()
+ files = []
+ # Process the user's messages
+ message = [message for message in messages if message['author']['id'] in user_id][0]
+ cmd = message['content']
+
+ #detect files
+ if len(messages[0]['attachments']) > 0:
+ for attachment in messages[0]['attachments']:
+ try:
+ file = attachment['url']
+ files.append(file)
+ cmd = "webfile " + str(files)
+ except:
+ pass
+ if message['id'] != old_id:
+ try:
+ old_id = message['id']
+ while cmd == None:
+ main()
+ return cmd
+ except:
+ sleep(0.1)
+ main()
+ else:
+ sleep(0.1)
+ main()
+ else:
+ #return f'Error: {response.status_code}' # response.text
+ sleep(0.25)
+ main()
+ main()
+
+
+if __name__ == "__main__":
+ cache = None
+ while 1:
+ while cache == None:
+ cache = main()
+ print(cache)
+ cache = main()
+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())
+