-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
122 lines (96 loc) · 3.42 KB
/
Copy pathmain.py
File metadata and controls
122 lines (96 loc) · 3.42 KB
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
114
115
116
117
118
119
120
121
122
import discord
from discord.ext import commands
import os
from cogs.shared import log
from ConfigLoader import load_config
from cogs.tickets import TicketPanelView
from cogs.tickets import TicketCloseView
print(discord.__version__)
print(hasattr(discord.ui, "channel_select"))
print([x for x in dir(discord.ui) if "select" in x.lower()])
# Load optional .env (still works for local dev)
try:
from dotenv import load_dotenv
load_dotenv()
except Exception:
pass
DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")
DB_PATH = os.getenv("DB_PATH", "bot.db")
LOG_PATH = os.getenv("LOG_PATH", "./logs")
# Optional safety check
if not DISCORD_TOKEN:
raise RuntimeError("DISCORD_TOKEN is not set in environment variables")
CONFIG = load_config()
DEV_GUILD_ID = 1254318703554723901
intents = discord.Intents.default()
intents.message_content = True
intents.presences = True
intents.members = True
intents.messages = True
class MyBot(commands.Bot):
def __init__(self):
super().__init__(
command_prefix=CONFIG["general"]["prefix"],
intents=intents
)
# attach shared runtime config (useful in cogs)
self.config = CONFIG
self.db_path = DB_PATH
self.log_path = LOG_PATH
async def setup_hook(self):
# Load cogs
await self.load_extension("cogs.logs")
await self.load_extension("cogs.utility")
await self.load_extension("cogs.config")
await self.load_extension("cogs.database")
await self.load_extension("cogs.FlagManager")
await self.load_extension("cogs.SuspiciousKeywords")
await self.load_extension("cogs.moderation")
await self.load_extension("cogs.image_filter")
await self.load_extension("cogs.LinkSpam")
await self.load_extension("cogs.MassMentionPrevention")
await self.load_extension("cogs.DoubleExtensionPrevention")
await self.load_extension("cogs.Setup")
await self.load_extension("cogs.links_filter")
await self.load_extension("cogs.words_filter")
await self.load_extension("cogs.giveaway")
await self.load_extension("cogs.tickets")
await self.load_extension("cogs.events")
await self.load_extension("cogs.announcements")
self.add_view(TicketPanelView())
self.add_view(TicketPanelView())
dev_guild = discord.Object(id=DEV_GUILD_ID)
try:
# Sync / commands to dev guild
await self.tree.sync(guild=dev_guild)
# Sync / commands globally
await self.tree.sync()
except Exception as e:
print(f"Sync failed: {e}")
bot = MyBot()
@bot.event
async def on_ready():
status_type = CONFIG["general"]["status_type"].lower()
status_text = CONFIG["general"]["status_text"]
if status_type == "playing":
activity = discord.Game(name=status_text)
elif status_type == "watching":
activity = discord.Activity(
type=discord.ActivityType.watching,
name=status_text
)
elif status_type == "listening":
activity = discord.Activity(
type=discord.ActivityType.listening,
name=status_text
)
else:
raise ValueError(
f"Invalid status_type in config.yml: {status_type}"
)
await bot.change_presence(
activity=activity,
status=discord.Status.online
)
print(f"Logged in as {bot.user}")
bot.run(DISCORD_TOKEN)