クイックスタート¶

このページでは、Discord アプリケーションを作成してサーバーに追加し、スラッシュコマンドを 1 つ持つ Bot を動かします。bostie がインストール済みであることを前提とします。
AI コーディングアシスタントをお使いですか?
bostie スキルをインストールすると、コーディングアシスタントが bostie を使う作業をより正確にこなせるようになります。プロンプトをコピーして、コーディングアシスタントに貼り付けてください。 スキルの詳細
bostie スキルをインストールする
Install the bostie skill for my coding agent so it writes correct bostie code: Discord bots with slash commands, components, events, REST calls, voice and tests.
Use the Agent Skills installer with the bostie repository, https://github.com/nicokim/bostie:
npx skills add nicokim/bostie --skill bostie --yes
If I ask for a global install instead, use:
npx skills add nicokim/bostie --skill bostie --yes --global
Detect which agent or editor I am using. If it is one of these and I prefer the plugin path, install the bostie plugin instead, as https://bostie.dev/ja/assistants/ shows:
Claude Code: /plugin marketplace add nicokim/bostie, then /plugin install bostie@bostie
Codex CLI: codex plugin marketplace add nicokim/bostie, then codex plugin add bostie@bostie
GitHub Copilot CLI: copilot plugin marketplace add nicokim/bostie, then copilot plugin install bostie@bostie
VS Code with GitHub Copilot: run "Chat: Install Plugin from Source" and enter nicokim/bostie
Devin: devin plugins install nicokim/bostie#docs
Factory Droid: droid plugin marketplace add nicokim/bostie, then droid plugin install bostie@bostie --scope user
Qwen Code: qwen extensions install nicokim/bostie:bostie
Do not invent other skill names or install URLs.
Then add this line to the instructions file you read at the start of every session (AGENTS.md at the project root, or your global one for a global install), and create the file if needed:
Before you write or change code that uses bostie, look at how the project is laid out, then load the bostie skill.
After installing, confirm that the bostie skill is available to you.
アプリケーションを作成する¶
- Developer Portal を開き、アプリケーションを作成します。
- アプリケーションの Bot ページでトークンをリセットし、コピーします。トークンを持つ人は誰でも Bot を操作できるため、コードやリポジトリには含めないでください。
- Installation ページで、サーバーインストールに
applications.commandsとbotのスコープを追加します。次にインストールリンクを開き、自分が管理するサーバーにアプリを追加します。
Bot を書く¶
次の内容を bot.py として保存します。
import bostie
from bostie import Context
bot = bostie.Bot()
@bot.command
async def hello(ctx: Context) -> None:
"""Say hello."""
await ctx.respond(f"Hello, {ctx.user.display_name}!")
bot.run()
@bot.command は、関数をスラッシュコマンド /hello に変えます。コマンド名は関数名、説明は docstring の 1 行目です。ctx はコマンドの 1 回の使用を表す Context で、誰がどこで実行したか、そして応答するためのメソッドを持ちます。
実行する¶
トークンを環境変数 BOSTIE_TOKEN で渡し、ファイルを実行します。
export BOSTIE_TOKEN="your token"
python bot.py
bot.run() は INFO レベルでロギングを設定して接続し、定義したコマンドと Discord に登録済みのコマンドを比較します。初回の起動では /hello を登録して commands synced (global): added ['hello'], ... をログに出力します。以降の起動では、コマンドが変わらない限り何も送信しません。サーバーで /hello と入力すると、Bot が応答します。
Ctrl+C、またはプロセスマネージャーからの SIGTERM で、Bot はきれいに終了します。
オプションを追加する¶
ctx の後に続くパラメーターはコマンドのオプションになり、その型は型ヒントで決まります。
import secrets
import bostie
from bostie import Context, Range
bot = bostie.Bot()
@bot.command
async def roll(ctx: Context, sides: Range[int, 2, 100] = 6) -> None:
"""Roll a die."""
rolled = secrets.randbelow(sides) + 1
await ctx.respond(f"You rolled {rolled} on a d{sides}.")
bot.run()
sides は 2 から 100 までの整数オプションで、既定値は 6 です。そのため Discord はこれを省略可能なオプションとして表示し、範囲外の値は Bot に届く前に拒否します。Bot を再起動すると、変更したコマンドが送信されます。
次のステップ¶
- スラッシュコマンドでは、すべてのオプションの型、選択肢、オートコンプリート、サブコマンドを扱います。
- インタラクションへの応答では、
respond、遅延応答、フォローアップ、エフェメラルな応答を説明します。 - コマンドの登録では、作業中のコマンドを 1 つのテスト用サーバーに登録する方法を示します。
- Bot の実行では、トークン、ロギング、Bot のライフサイクル、ほかのプログラムの中で Bot を動かす方法を扱います。