This repository was archived by the owner on Apr 13, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.py
More file actions
129 lines (108 loc) · 5.43 KB
/
Main.py
File metadata and controls
129 lines (108 loc) · 5.43 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import discord
from discord.ext import commands
from Modules import Blacklist
from Modules import Commands
from discord_slash import SlashCommand, SlashContext
from discord_slash.utils.manage_commands import create_option
import requests
import json
#parameters
intents = discord.Intents.default()
intents.members = True
client = commands.Bot(command_prefix='/', intents = intents)
slash = SlashCommand(client, sync_commands=True)
guilds = []
@client.event
async def on_ready():
print(f"Logged as {client.user}")
for guild in client.guilds:
guilds.append(guild.id)
@slash.slash(
name="blacklist",
description="If you are an admin, you are able to blacklist an user",
guild_ids=[876954462768480296], #I need to think about it
)
async def blackList(ctx, member:str, details:object):
print(member)
print(details)
try:
r = requests.get(f'https://discord.com/api/v8/users/{member}', headers={'Authorization': 'Bot ODc2OTU1NDk0NTc1NjYxMDc2.YRrmcg.3UeZM1n1sG94ohmcwqBKGocJjGQ'})
toDecode = json.loads(r.text)
y = {
"memberid": toDecode["id"],
"details": details,
"name": toDecode["username"],
"discriminator": toDecode["discriminator"],
"avatar": f'https://cdn.discordapp.com/avatars/{toDecode["id"]}/{toDecode["avatar"]}.png?size=1024'
}
embedVar = discord.Embed(title=f'{toDecode["username"]}#{toDecode["discriminator"]} / {toDecode["id"]}', description=f'The user **{toDecode["username"]}#{toDecode["discriminator"]}** with id {toDecode["id"]} has been blacklisted with reason **{details}**', color=0x00ff00)
msg = await ctx.send("**Adding to blacklist...**")
embedVar.set_thumbnail(url=f'https://cdn.discordapp.com/avatars/{toDecode["id"]}/{toDecode["avatar"]}.png?size=1024')
write_json(y)
await msg.delete()
await ctx.channel.send(embed=embedVar)
except:
msg = await ctx.send("**This user is not valid**")
@slash.slash(
name="checkuser",
description="Check the status of an user",
guild_ids=[876954462768480296], #I need to think about it
)
async def checkUser(ctx, member:str):
user = getUser(member)
blacklisted = False
with open("Blacklisted.json",'r+') as file:
toRead = json.load(file)
msg = await ctx.send("**Checking user...**")
await msg.delete()
for bl in toRead["blacklisted"]:
print(bl["memberid"])
if str(bl["memberid"]) == str(user):
r = requests.get(f'https://discord.com/api/v8/users/{user}', headers={'Authorization': 'Bot ODc2OTU1NDk0NTc1NjYxMDc2.YRrmcg.3UeZM1n1sG94ohmcwqBKGocJjGQ'})
print(r.text)
toDecode = json.loads(r.text)
embedVar = discord.Embed(title=f'**{toDecode["username"]}#{toDecode["discriminator"]}**', description=f'The user **{toDecode["username"]}#{toDecode["discriminator"]}** with id {toDecode["id"]} is blacklisted with the reason **{bl["details"]}**', color=0xff0000)
embedVar.set_thumbnail(url=f'https://cdn.discordapp.com/avatars/{toDecode["id"]}/{toDecode["avatar"]}.png?size=1024')
channel = client.get_channel(876954462768480299)
blacklisted = True
await channel.send(embed=embedVar)
break
if not blacklisted:
try:
r = requests.get(f'https://discord.com/api/v8/users/{user}', headers={'Authorization': 'Bot ODc2OTU1NDk0NTc1NjYxMDc2.YRrmcg.3UeZM1n1sG94ohmcwqBKGocJjGQ'})
print(r.text)
toDecode = json.loads(r.text)
embedVar = discord.Embed(title=f'**{toDecode["username"]}#{toDecode["discriminator"]}**', description=f'The user **{toDecode["username"]}#{toDecode["discriminator"]}** with id {toDecode["id"]} is not blacklisted', color=0x00ff00)
channel = client.get_channel(876954462768480299)
embedVar.set_thumbnail(url=f'https://cdn.discordapp.com/avatars/{toDecode["id"]}/{toDecode["avatar"]}.png?size=1024')
blacklisted = True
await channel.send(embed=embedVar)
except:
msg = await ctx.send("**This user is not valid**")
def getUser(member):
x = member.replace("<", "")
x = x.replace(">", "")
x = x.replace("!", "")
x = x.replace("@", "")
return x
@client.event
async def on_member_join(member):
print(f'{member.guild.id} has joined a server.')
with open("Blacklisted.json",'r+') as file:
toRead = json.load(file)
for bl in toRead["blacklisted"]:
print(bl["memberid"])
if str(bl["memberid"]) == str(member.id):
embedVar = discord.Embed(title="Title", description="Blacklisted user", color=0x00ff00)
embedVar.set_thumbnail(url=f'https://cdn.discordapp.com/avatars/{toDecode["id"]}/{toDecode["avatar"]}.png?size=1024')
embedVar.add_field(name="Status", value=f'The user {member.name} is blacklisted', inline=False)
channel = client.get_channel(876954462768480299)
await channel.send(embed=embedVar)
break
def write_json(new_data, filename='Blacklisted.json'):
with open(filename,'r+') as file:
file_data = json.load(file)
file_data["blacklisted"].append(new_data)
file.seek(0)
json.dump(file_data, file, indent = 4)
client.run('ODc2OTU1NDk0NTc1NjYxMDc2.YRrmcg.3UeZM1n1sG94ohmcwqBKGocJjGQ')