-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
70 lines (52 loc) · 2.14 KB
/
main.py
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
63
64
65
66
67
68
69
70
import json
import discord
# load variables
import os
from dotenv import load_dotenv
dotenv_path = os.path.join(os.path.dirname(__file__), '.env')
if os.path.exists(dotenv_path):
load_dotenv(dotenv_path)
TOKEN = os.getenv("TOKEN")
CHAT_ID = os.getenv("CHAT_ID")
YOUR_ID = os.getenv("YOUR_ID")
intents = discord.Intents.default()
intents.message_content = True
client = discord.Client(intents=intents)
@client.event
async def on_ready():
print(f'We have logged in as {client.user}')
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('/check'):
# get channel by id
channel = client.get_channel(CHAT_ID)
# validation (must contain limit value and '/check' word )
if len(message.content.split(' ')) != 2:
await channel.send('Wrong number of parameters\nExample: ```/check 5```\nMaximum value is 100 messages')
else:
if int(message.content.split(' ')[1]) > 100:
limit = 100
else:
limit = int(message.content.split(' ')[1])
# get messages from new to old
async for message in channel.history(limit=limit):
info = {}
print(f'Message id: {message.id} || Author: {message.author.name} || Author ID: {message.author.id}')
info['Message id'] = message.id
info['Author'] = message.author.name
info['Author ID'] = message.author.id
info['Reacted users'] = []
for reaction in message.reactions:
async for user in reaction.users():
info['Reacted users'].append({"Name": user.name, "User ID": user.id,
"Created at": user.created_at.strftime("%m/%d/%Y, %H:%M:%S")})
# Send in channel
# await channel.send(json.dumps(info))
# Send in DM
user = await client.fetch_user(YOUR_ID)
await user.send(json.dumps(info))
if __name__ == '__main__':
print(TOKEN)
client.run(TOKEN)