-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
62 lines (44 loc) · 1.48 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
from __future__ import annotations
import logging
import os
import traceback
from typing import Any, Optional
import discord
from discord.ext import commands
from dotenv import load_dotenv
from cogs import EXTENSIONS
from command_tree import JDCommandTranslator, JDCommandTree
class JDBot(commands.Bot):
tree: JDCommandTree # type: ignore
def __init__(self, *args: Any, **kwargs: Any) -> None:
super().__init__(*args, **kwargs)
async def setup_hook(self) -> None:
for cog in EXTENSIONS:
try:
await self.load_extension(f"{cog}")
except commands.errors.ExtensionError:
traceback.print_exc()
await self.tree.set_translator(JDCommandTranslator())
async def try_user(self, id: int, /) -> Optional[discord.User]:
maybe_user = self.get_user(id)
if maybe_user is not None:
return maybe_user
try:
return await self.fetch_user(id)
except discord.errors.NotFound:
return None
intents = discord.Intents(guilds=True, messages=True, message_content=True)
bot = JDBot(
command_prefix=commands.when_mentioned_or("h$"),
intents=intents,
chunk_guilds_at_startup=False,
strip_after_prefix=True,
allowed_mentions=discord.AllowedMentions(everyone=False, roles=False),
)
@bot.event
async def on_ready():
print(bot.user)
print(bot.user.id)
load_dotenv()
logging.basicConfig(level=logging.INFO)
bot.run(os.environ["TOKEN"])