-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
113 lines (83 loc) · 2.75 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
"""
Welcome 👋🏼!
This repl contains all of source code of the GalGuard Discord bot.
Please consider adding our bot to your discord server to support our work.
Invite link: https://discord.com/api/oauth2/authorize?client_id=963457369310916678&permissions=8&scope=bot (copy and paste into browser)
😊 Happy coding!
— Sincerely, FoxyCoder (co-owner of the bot)
"""
#[----------IMPORTS----------]
import discord
from discord.ext import commands
import os
import json
from Cogs.init import Init
from Cogs.info import Info
from Cogs.moderation import Moderation
from Cogs.errors import Errors
from Cogs.fun import Fun
from Cogs.math import Math
from Cogs.giveaways import Giveaways
from Cogs.bomb import Bomb
from hosting import keep_alive
from datetime import datetime
from datetime import date
import time
from discord_ui import Components, Button, UI
#[----------PREFIXES----------]
def get_prefix(client, message):
with open('prefixes.json', 'r') as f:
prefixes = json.load(f)
return prefixes[str(message.guild.id)]
#[----------BOT----------]
client = commands.Bot(command_prefix=get_prefix, help_command=None)
ui = UI(client)
#[----------EVENTS----------]
@client.event
async def on_ready():
print("✅ Main.py loaded!")
#client.process_commands(message)
# ^^^ add to every event ^^^
#[----------COMMANDS----------]
@client.event
async def on_guild_join(guild):
with open('prefixes.json', 'r') as f:
prefixes = json.load(f)
prefixes[str(guild.id)] = '?'
with open('prefixes.json', 'w') as f:
json.dump(prefixes, f, indent=4)
@client.event
async def on_guild_remove(guild):
with open('prefixes.json', 'r') as f:
prefixes = json.load(f)
prefixes.pop(str(guild.id))
with open('prefixes.json', 'w') as f:
json.dump(prefixes, f, indent=4)
@client.command()
async def set_prefix(ctx, prefix):
with open('prefixes.json', 'r') as f:
prefixes = json.load(f)
prefixes[str(ctx.guild.id)] = prefix
await ctx.send(f"> ✅ **Prefix has been updated to `{prefix}`.**")
with open('prefixes.json', 'w') as f:
json.dump(prefixes, f, indent=4)
@client.command()
async def test(ctx):
await ctx.send("> ✅ **Bot is operational, running all cogs.**")
@client.command()
async def ping(ctx):
await ctx.send(
f">>> ⌛ Bot's current latency is **{client.latency * 1000}** ms.")
client.add_cog(Init(client))
client.add_cog(Info(client))
client.add_cog(Moderation(client))
client.add_cog(Errors(client))
#client.add_cog(Translate(client))
client.add_cog(Fun(client))
client.add_cog(Math(client))
client.add_cog(Bomb(client))
client.add_cog(Giveaways(client))
#[----------LOGGING IN----------]
keep_alive()
tokenvar = os.environ['token']
client.run(tokenvar)