blob: 2fc5f3b42ad11def1773e9f630bc0929ecc6823e (
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
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()
if __name__ == "__main__":
cache = None
while 1:
while cache == None:
cache = main()
print(cache)
cache = main()
|