Início rápido¶

Esta página cria um aplicativo no Discord, adiciona-o a um servidor e roda um bot com um comando de barra. Ela supõe que o bostie já está instalado.
Usa um assistente de programação com IA?
Instale a skill do bostie para que o seu assistente de programação se saia melhor em tarefas com o bostie. Copie o prompt e cole-o no seu assistente de programação. Mais sobre a skill
Instalar a skill do 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/pt-br/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.
Crie o aplicativo¶
- Abra o Developer Portal e crie um aplicativo.
- Na página Bot dele, redefina o token e copie-o. Quem tem o token controla o bot, então mantenha-o fora do seu código e do seu repositório.
- Na página Installation dele, adicione os escopos
applications.commandsebotà instalação no servidor, depois abra o link de instalação e adicione o app a um servidor que você administra.
Escreva o bot¶
Salve isto como 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 transforma a função no comando de barra /hello. O nome dele é o nome da função e a descrição é a primeira linha da docstring. ctx é o Context de um uso do comando: quem o executou, onde, e os métodos que respondem.
Rode o bot¶
Passe o token pela variável de ambiente BOSTIE_TOKEN e execute o arquivo:
export BOSTIE_TOKEN="your token"
python bot.py
bot.run() configura o logging em INFO, conecta e compara os comandos que você definiu com os registrados no Discord. A primeira execução registra /hello e escreve no log commands synced (global): added ['hello'], ...; as execuções seguintes não enviam nada, a menos que um comando tenha mudado. Digite /hello no seu servidor e o bot responde.
Ctrl+C, ou um SIGTERM vindo de um gerenciador de processos, encerra o bot de forma limpa.
Adicione uma opção¶
Os parâmetros depois de ctx viram as opções do comando, com o tipo dado pelas anotações:
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 é uma opção inteira de 2 a 100 com padrão 6, então o Discord a mostra como opcional e recusa valores fora do intervalo antes que o bot os veja. Reinicie o bot e ele envia o comando alterado.
Próximos passos¶
- Comandos de barra cobre todos os tipos de opção, escolhas, preenchimento automático e subcomandos.
- Respondendo a interações explica
respond, como adiar a resposta, mensagens de acompanhamento e respostas efêmeras. - Registrando comandos mostra como registrar comandos em um servidor de teste enquanto você trabalha neles.
- Rodando um bot cobre o token, o logging, o ciclo de vida do bot e como rodá-lo dentro de outro programa.