-
Notifications
You must be signed in to change notification settings - Fork 7
/
bot.py
executable file
·51 lines (34 loc) · 1.09 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
#!/usr/bin/env python
import argparse
import json
import discord
from discord import app_commands
from commands import install_commands
from handlers.message_handler import MessageHandler
class HearthBotClient(discord.Client):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.tree = app_commands.CommandTree(self)
async def setup_hook(self):
await self.tree.sync()
def main():
p = argparse.ArgumentParser()
p.add_argument("--config", required=True, help="Path to configuration file")
args = p.parse_args()
with open(args.config, "r") as f:
config = json.load(f)
intents = discord.Intents.default()
activity = discord.CustomActivity("DM me !help or !invite")
client = HearthBotClient(intents=intents, activity=activity)
install_commands(config, client)
@client.event
async def on_ready():
print("Logged in as", client.user.name)
# Legacy commands
message_handler = MessageHandler(config, client)
@client.event
async def on_message(message):
await message_handler.handle(message)
client.run(config["token"])
if __name__ == "__main__":
main()