-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbot.py
94 lines (70 loc) · 2.32 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
82
83
84
85
86
87
88
89
90
91
92
93
94
import asyncio
import os
import random
import tomllib
import discord
from discord.ext import commands, tasks
from pretty_help import PrettyHelp
with open("config.toml", "rb") as f:
config = tomllib.load(f)
async def main():
# start the client
async with client:
for filename in os.listdir("./cogs"):
if filename.endswith(".py"):
await client.load_extension(f"cogs.{filename[:-3]}")
await client.start(config["general"]["token"])
intents = discord.Intents().all()
client = commands.Bot(
command_prefix=config["general"]["prefix"],
intents=intents,
help_command=PrettyHelp(),
)
@tasks.loop(seconds=30)
async def change_status():
statuses = [
",help | ,invite",
f"Currently in {len(client.guilds)} guilds",
f"I can see {len(client.users)} users",
]
await client.change_presence(activity=discord.Game(random.choice(statuses)))
@client.command(hidden=True)
async def load(ctx, extension):
if ctx.author.id == config["general"]["owner_id"]:
await client.load_extension(f"cogs.{extension}")
await ctx.send(f"{extension} loaded.")
if ctx.author.id != config["general"]["owner_id"]:
await ctx.send("no")
@client.command(hidden=True)
async def unload(ctx, extension):
if ctx.author.id == config:
await client.unload_extension(f"cogs.{extension}")
await ctx.send(f"{extension} unloaded.")
if ctx.author.id != config["general"]["owner_id"]:
await ctx.send("no")
@client.command(hidden=True)
async def reload(ctx, extension):
if ctx.author.id == config["general"]["owner_id"]:
await client.unload_extension(f"cogs.{extension}")
await ctx.send(f"{extension} unloaded.")
await client.load_extension(f"cogs.{extension}")
await ctx.send(f"{extension} loaded.")
else:
await ctx.send("no")
async def guilds():
return client.guilds
async def users():
return client.users
@client.event
async def on_ready():
print("I am ready.")
change_status.start()
try:
synced = await client.tree.sync()
print(f"Sycned {len(synced)} commands!")
except Exception as e:
print(e)
if not os.path.exists("data/database.sqlite"):
open("data/database.sqlite", "w").close()
discord.utils.setup_logging()
asyncio.run(main())