edit 使用 .env 方式修改頻道ID
This commit is contained in:
parent
3b948c5fda
commit
029fee16ea
|
|
@ -4,4 +4,8 @@ DISCORD_BOT_TOKEN=your_bot_token_here
|
|||
|
||||
# Discord Application ID (可選)
|
||||
# 用於 Slash Commands
|
||||
DISCORD_APPLICATION_ID=your_application_id_here
|
||||
DISCORD_APPLICATION_ID=your_application_id_here
|
||||
|
||||
# Discord Guild ID (可選)
|
||||
# 用於限制 Slash Commands 只在特定伺服器可用
|
||||
GUILD_ID=your_guild_id_here
|
||||
|
|
@ -1,12 +1,19 @@
|
|||
import os
|
||||
import discord
|
||||
import random
|
||||
import json
|
||||
import asyncio
|
||||
import datetime
|
||||
from dotenv import load_dotenv
|
||||
from discord.ext import commands
|
||||
from discord import app_commands
|
||||
from discord import FFmpegPCMAudio
|
||||
|
||||
# 載入 .env 檔案
|
||||
load_dotenv()
|
||||
# 從環境變數讀取 Guild ID 並轉型為 int
|
||||
MY_GUILD_ID = int(os.getenv('GUILD_ID'))
|
||||
|
||||
class Lottery(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
|
|
@ -22,7 +29,7 @@ class Lottery(commands.Cog):
|
|||
self.stop = False
|
||||
|
||||
# --- 建立抽選清單 ---
|
||||
@app_commands.guilds(discord.Object(id=605678541530726421))
|
||||
@app_commands.guilds(discord.Object(id=MY_GUILD_ID))
|
||||
@app_commands.command(name="建立抽選清單", description="建立寶可夢或動畫角色的抽選清單")
|
||||
@app_commands.choices(list_name=[
|
||||
app_commands.Choice(name="寶可夢", value="寶可夢"),
|
||||
|
|
@ -48,7 +55,7 @@ class Lottery(commands.Cog):
|
|||
await interaction.response.send_message(msg, ephemeral=True)
|
||||
|
||||
# --- 顯示清單狀態 ---
|
||||
@app_commands.guilds(discord.Object(id=605678541530726421))
|
||||
@app_commands.guilds(discord.Object(id=MY_GUILD_ID))
|
||||
@app_commands.command(name="抽選清單", description="檢視所有抽選清單及目前抽選狀態")
|
||||
async def show_list(self, interaction: discord.Interaction):
|
||||
pokeCount = self.getPokeCount + 1
|
||||
|
|
@ -59,7 +66,7 @@ class Lottery(commands.Cog):
|
|||
)
|
||||
|
||||
# --- 抽寶可夢 ---
|
||||
@app_commands.guilds(discord.Object(id=605678541530726421))
|
||||
@app_commands.guilds(discord.Object(id=MY_GUILD_ID))
|
||||
@app_commands.command(name="抽寶可夢", description="顯示題目,並於指定秒數後公布答案圖片")
|
||||
@app_commands.describe(t="倒數秒數(需大於5)")
|
||||
async def get_poke(self, interaction: discord.Interaction, t: int):
|
||||
|
|
@ -97,7 +104,7 @@ class Lottery(commands.Cog):
|
|||
await interaction.response.send_message("請先加入語音頻道", ephemeral=True)
|
||||
|
||||
# --- 抽動畫角色 ---
|
||||
@app_commands.guilds(discord.Object(id=605678541530726421))
|
||||
@app_commands.guilds(discord.Object(id=MY_GUILD_ID))
|
||||
@app_commands.command(name="抽動畫角色", description="顯示題目,並於指定秒數後公布答案圖片")
|
||||
@app_commands.describe(t="倒數秒數(需大於5)")
|
||||
async def get_ani(self, interaction: discord.Interaction, t: int):
|
||||
|
|
@ -135,7 +142,7 @@ class Lottery(commands.Cog):
|
|||
await interaction.response.send_message("請先加入語音頻道", ephemeral=True)
|
||||
|
||||
# --- 新增:動畫角色單一複習 ---
|
||||
@app_commands.guilds(discord.Object(id=605678541530726421))
|
||||
@app_commands.guilds(discord.Object(id=MY_GUILD_ID))
|
||||
@app_commands.command(name="動畫角色複習", description="顯示指定編號的角色")
|
||||
@app_commands.describe(num="想要查看的角色編號 (從 1 開始)")
|
||||
async def check_ani(self, interaction: discord.Interaction, num: int = 1):
|
||||
|
|
@ -151,7 +158,7 @@ class Lottery(commands.Cog):
|
|||
await interaction.response.send_message(embed=embed)
|
||||
|
||||
# --- 新增:動畫角色總複習 ---
|
||||
@app_commands.guilds(discord.Object(id=605678541530726421))
|
||||
@app_commands.guilds(discord.Object(id=MY_GUILD_ID))
|
||||
@app_commands.command(name="動畫角色總複習", description="每 2 秒顯示一位動畫角色,直到結束")
|
||||
async def check_all_ani(self, interaction: discord.Interaction):
|
||||
self.stop = False
|
||||
|
|
@ -177,7 +184,7 @@ class Lottery(commands.Cog):
|
|||
await interaction.followup.send("複習完畢!")
|
||||
|
||||
# --- 停止複習 ---
|
||||
@app_commands.guilds(discord.Object(id=605678541530726421))
|
||||
@app_commands.guilds(discord.Object(id=MY_GUILD_ID))
|
||||
@app_commands.command(name="停止", description="停止顯示總複習清單")
|
||||
async def stop_check_all_ani(self, interaction: discord.Interaction):
|
||||
self.stop = True
|
||||
|
|
|
|||
Loading…
Reference in New Issue