Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

CSIE-CAMP-2026-bot

師大資工系學會 CSIE Camp 2026 使用的 Discord 機器人,基於 discord.py。


部署方式(開發者必讀)

流程概覽

push 到 main → GitHub Actions 觸發 → Self-hosted Runner(系學會伺服器)
    → rsync 到 /home/CBC/CSIE-CAMP-2026-bot
    → pip install -r requirements.txt
    → systemctl restart csie-camp-bot(若有)
  • CI 設定:.github/workflows/deploy.yml
  • Runner:在系學會伺服器 main-csie-sa 上,runs-on: [self-hosted]
  • 部署目錄:/home/CBC/CSIE-CAMP-2026-bot
  • 排除:.env、node_modules、__pycache__、venv 不會被 rsync 覆蓋

如何發布

  1. 開發完成後 push 到 main 即會自動部署。
  2. 若伺服器已建立 csie-camp-bot systemd 服務,部署後會自動 restart;若尚未建立,只會同步檔案與安裝依賴,不會報錯。

伺服器上的 .env

.env 不會 從 Git 部署上去,須在系學會伺服器上自行建立:

ssh sa
nano /home/CBC/CSIE-CAMP-2026-bot/.env
# 填入 DISCORD_TOKEN=... 等,見下方「環境變數」

協作與權限

  • 具 Repo Write 權限的成員可 push 到 main, push 即觸發部署。
  • 無需 SSH 或伺服器帳號;部署全由 GitHub Actions + Self-hosted Runner 處理。

本地開發

1. 克隆與依賴

git clone https://github.com/CSIE-Camp/CSIE-CAMP-2026-bot.git
cd CSIE-CAMP-2026-bot
python -m venv venv
source venv/bin/activate   # Windows: venv\Scripts\activate
pip install -r requirements.txt

2. 建立 Bot 與邀請

  1. Discord Developer Portal → New Application → 取名(例如 CSIE-CAMP-2026-bot)
  2. 左側 Bot → Add Bot → Reset Token 並複製(即 DISCORD_TOKEN)
  3. 左側 OAuth2 → URL Generator:
    • Scopes:勾選 bot、applications.commands
    • Bot Permissions:依需求勾選(例如「傳送訊息」、「讀取訊息記錄」)
    • 複製下方網址,在瀏覽器開啟,選擇你的測試伺服器完成邀請

3. 環境變數

複製範例並修改:

cp .env.example .env
# 編輯 .env,至少填入 DISCORD_TOKEN
變數 必填 說明
DISCORD_TOKEN 是 Developer Portal → 你的 Application → Bot → Reset Token / Copy
GUILD_ID 否 測試用 Discord 伺服器 ID;有設則 slash 只同步到該伺服器(數分鐘),不設則同步到全域(約 1 小時)。開發者模式 → 對伺服器右鍵 → 複製伺服器 ID

4. 執行

python main.py

看到 Bot 已上線 即表示連線成功;在 Discord 輸入 / 可看到 /ping、/hello。


專案結構

CSIE-CAMP-2026-bot/
├── .github/
│   └── workflows/
│       └── deploy.yml    # push main 時自動部署
├── main.py               # 機器人進入點
├── requirements.txt
├── .env.example
├── .gitignore
└── README.md

擴充建議

  • 新增 cogs:在 main.py 用 client.load_extension("cogs.xxx") 掛載(若改用 commands.Bot 則對應改為 bot.load_extension)。
  • 新增 slash 指令:在 main.py 的 tree 上使用 @tree.command(),或寫在 cogs 裡用 app_commands。
  • 共用的設定、常數可放在 config.py,由 main.py 引入。

環境需求

  • Python 3.10+
  • discord.py 2.x(見 requirements.txt)

相關連結

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages