-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbot.py
81 lines (65 loc) · 2.29 KB
/
bot.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
71
72
73
74
75
76
77
78
79
80
81
import discord
import ezcord
from discord.ext.ipc import ClientPayload, Server
class Bot(ezcord.Bot):
def __init__(self):
intents = discord.Intents.default()
intents.members = True
super().__init__(intents=intents)
self.ipc = Server(self, secret_key="keks")
self.load_cogs()
async def on_ready(self):
await self.ipc.start()
print(f"{self.user} ist online")
@Server.route()
async def guild_count(self, _):
return str(len(self.guilds))
@Server.route()
async def bot_guilds(self, _):
guild_ids = [str(guild.id) for guild in self.guilds]
return {"data": guild_ids}
@Server.route()
async def guild_stats(self, data: ClientPayload):
guild = self.get_guild(data.guild_id)
if not guild:
return {
"member_count": 69,
"name": "Unbekannt"
}
return {
"member_count": guild.member_count,
"name": guild.name,
}
@Server.route()
async def check_perms(self, data: ClientPayload):
guild = self.get_guild(data.guild_id)
if not guild:
return {"perms": False}
member = guild.get_member(int(data.user_id))
if not member or not member.guild_permissions.administrator:
return {"perms": False}
return {"perms": True}
@Server.route()
async def get_guild_items(self,data: ClientPayload):
guild = self.get_guild(data.guild_id)
if not guild:
return {
"channels": [],
"roles": [],
"members": [],
}
return {
"channels": [str(channel.id)+" " + channel.name for channel in guild.channels],
"roles": [str(role.id) + " " + role.name for role in guild.roles],
"members": [str(member.id) + " " + member.name for member in guild.members],
}
@Server.route()
async def get_channel_name(self, data: ClientPayload):
print("Klappt")
guild = self.get_guild(data.guild_id)
channel = guild.get_channel(data.channel_id)
return channel.name
async def on_ipc_error(self, endpoint: str, exc: Exception) -> None:
raise exc
bot = Bot()
bot.run("TOKEN") # Hier den Bot-Token einfügen