Compare commits
No commits in common. "054a7e62dd7a235bbbb4800dce53965a8df80b5a" and "4378a8d572e33dc0e024b1cb8ba1fbccc591505b" have entirely different histories.
054a7e62dd
...
4378a8d572
17
Dockerfile
17
Dockerfile
|
|
@ -1,17 +0,0 @@
|
|||
# 使用輕量級的 Python 映像檔
|
||||
FROM python:3.11-slim
|
||||
|
||||
# 設定容器內的工作目錄
|
||||
WORKDIR /app
|
||||
|
||||
# 先複製需求文件,利用 Docker 快取機制加速打包
|
||||
COPY requirements.txt .
|
||||
|
||||
# 安裝必要的套件
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# 複製其餘的程式碼到容器內
|
||||
COPY . .
|
||||
|
||||
# 執行你的 Discord Bot
|
||||
CMD ["python", "discord-bot.py"]
|
||||
11
cogs/base.py
11
cogs/base.py
|
|
@ -5,12 +5,7 @@ Base Cog - 基礎功能
|
|||
import discord
|
||||
from discord.ext import commands
|
||||
from discord import app_commands
|
||||
from dotenv import load_dotenv
|
||||
|
||||
# 載入 .env 檔案
|
||||
load_dotenv()
|
||||
# 從環境變數讀取 Guild ID 並轉型為 int
|
||||
MY_GUILD_ID = int(os.getenv('GUILD_ID'))
|
||||
|
||||
class Base(commands.Cog):
|
||||
"""基礎功能 Cog"""
|
||||
|
|
@ -19,7 +14,7 @@ class Base(commands.Cog):
|
|||
self.bot = bot
|
||||
|
||||
# --- Slash Commands ---
|
||||
@app_commands.guilds(discord.Object(id=MY_GUILD_ID))
|
||||
@app_commands.guilds(discord.Object(id=605678541530726421))
|
||||
@app_commands.command(name='info', description='顯示機器人資訊')
|
||||
async def slash_info(self, interaction: discord.Interaction):
|
||||
"""顯示機器人資訊"""
|
||||
|
|
@ -34,14 +29,14 @@ class Base(commands.Cog):
|
|||
embed.set_footer(text=f'由 Discord.py {discord.__version__} 驅動')
|
||||
await interaction.response.send_message(embed=embed)
|
||||
|
||||
@app_commands.guilds(discord.Object(id=MY_GUILD_ID))
|
||||
@app_commands.guilds(discord.Object(id=605678541530726421))
|
||||
@app_commands.command(name='ping', description='測試機器人連線')
|
||||
async def slash_ping(self, interaction: discord.Interaction):
|
||||
"""測試機器人連線"""
|
||||
latency = round(self.bot.latency * 1000)
|
||||
await interaction.response.send_message(f'🏓 Pong! 延遲: {latency}ms')
|
||||
|
||||
@app_commands.guilds(discord.Object(id=MY_GUILD_ID))
|
||||
@app_commands.guilds(discord.Object(id=605678541530726421))
|
||||
@app_commands.command(name='echo', description='回覆你的訊息')
|
||||
async def slash_echo(self, interaction: discord.Interaction, message: str):
|
||||
"""回覆你的訊息"""
|
||||
|
|
|
|||
|
|
@ -12,8 +12,6 @@ load_dotenv()
|
|||
|
||||
# 設定 bot token
|
||||
TOKEN = os.getenv('DISCORD_BOT_TOKEN')
|
||||
# 從環境變數讀取 Guild ID 並轉型為 int
|
||||
MY_GUILD_ID = int(os.getenv('GUILD_ID'))
|
||||
|
||||
# 設定 bot
|
||||
intents = discord.Intents.default()
|
||||
|
|
@ -44,7 +42,7 @@ async def on_ready():
|
|||
|
||||
# 同步 Slash Commands 到指定伺服器
|
||||
try:
|
||||
guild = discord.Object(id=MY_GUILD_ID)
|
||||
guild = discord.Object(id=605678541530726421)
|
||||
synced = await bot.tree.sync(guild=guild)
|
||||
print(f'✅ 已同步 {len(synced)} 個 Slash Commands 到伺服器 {guild.id}')
|
||||
for cmd in synced:
|
||||
|
|
|
|||
|
|
@ -1,14 +0,0 @@
|
|||
services:
|
||||
discord-bot:
|
||||
build: .
|
||||
container_name: my-discord-bot
|
||||
restart: always # 機器人當掉或伺服器重啟時會自動重啟
|
||||
env_file:
|
||||
- .env # 讀取你的 .env 檔案(如果有的話)
|
||||
volumes:
|
||||
- .:/app # (選配) 開發階段可以掛載目錄,修改程式碼不用重新 build
|
||||
logging: # 限制日誌大小,避免硬碟被塞爆
|
||||
driver: "json-file"
|
||||
options:
|
||||
max-size: "10mb"
|
||||
max-file: "3"
|
||||
Loading…
Reference in New Issue