-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.py
97 lines (77 loc) · 2.24 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
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
import discord
from discord.ext import commands
import config
from prettytable import PrettyTable
import os
import DiscordUtils
from discord_ui import UI
cogs = [
"general",
"post",
"youtube",
"mod",
"welcome",
"license",
"thx",
"errors",
"help",
"xp",
"search"
]
def get_prefix(bot, msg):
return commands.when_mentioned_or(config.prefix)(bot, msg)
client = commands.Bot(
command_prefix=get_prefix,
case_insensitive=True,
allowed_mentions=discord.AllowedMentions(
everyone=False,
users=True,
roles=False
),
intents=discord.Intents.all(),
owner_ids=config.owner_ids,
activity=discord.Activity(name='%shelp - discord.gg/ottawa' % config.prefix, type=discord.ActivityType.playing),
status=discord.Status.dnd
)
ui = UI(client)
client.tracker = DiscordUtils.InviteTracker(client)
client.remove_command('help')
if config.token == "" or config.token == "token":
client.token = os.environ['token']
else:
client.token = config.token
for filename in cogs:
try:
client.load_extension(f'cogs.{filename}')
print('lode {}'.format(filename))
except Exception as error:
print('error in {} as [{}]'.format(filename, error))
@client.event
async def on_invite_create(invite):
await client.tracker.update_invite_cache(invite)
@client.listen("on_guild_join")
async def on_guild_join(guild: discord.Guild):
if guild.id != config.guild_id:
await guild.leave()
@client.event
async def on_invite_delete(invite):
await client.tracker.remove_invite_cache(invite)
@client.event
async def on_ready():
# await ui.slash.delete_guild_commands("843865725886398554")
await client.tracker.cache_invites()
for guild in client.guilds:
if guild.id != config.guild_id:
await guild.leave()
tap = PrettyTable(
['Name Bot', 'Id', 'prefix', 'commands', 'users'])
tap.add_row([
client.user.display_name,
str(client.user.id),
"!",
len(client.commands),
len(client.users),
])
print(tap)
if __name__ == '__main__':
client.run(client.token, reconnect=True)