46 lines
1.2 KiB
Python
46 lines
1.2 KiB
Python
import os
|
|
|
|
import discord
|
|
from discord.ext import commands
|
|
|
|
from config import DEV_CHANNEL_ID, VERSION
|
|
|
|
EXTENSIONS = [
|
|
"cogs.signin",
|
|
"cogs.profile",
|
|
"cogs.settings",
|
|
"cogs.rank",
|
|
"cogs.lottery",
|
|
]
|
|
|
|
|
|
class GameBot(commands.Bot):
|
|
def __init__(self):
|
|
intents = discord.Intents.default()
|
|
intents.message_content = True # 偵測簽到表符
|
|
intents.members = True # 伺服器排行榜(需在 Developer Portal 開啟)
|
|
super().__init__(command_prefix=commands.when_mentioned, intents=intents)
|
|
self.announced = False
|
|
|
|
async def setup_hook(self):
|
|
for ext in EXTENSIONS:
|
|
await self.load_extension(ext)
|
|
await self.tree.sync()
|
|
|
|
async def on_ready(self):
|
|
print(f"Logged in as {self.user}")
|
|
# on_ready 在斷線重連後會再觸發,只通知一次
|
|
if self.announced:
|
|
return
|
|
self.announced = True
|
|
channel = self.get_channel(DEV_CHANNEL_ID)
|
|
if channel:
|
|
await channel.send(f"遊戲機已啟動,版本{VERSION}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
token = os.getenv("DISCORD_BOT_TOKEN")
|
|
if not token:
|
|
raise SystemExit("請設定環境變數 DISCORD_BOT_TOKEN")
|
|
GameBot().run(token)
|