Discord bot architect

From findscripter/everything-skills · View interactive version

Discord bot architect is an AI agent skill from the GitHub repository findscripter/everything-skills. 当用 Discord.js(JS/TS) 或 Pycord(Python) 搭建生产级 Discord 机器人时使用;做斜杠命令/交互组件/限流/分片的架构搭建并产出可运行骨架;不适用于 Slack 等其他平台或纯 LLM 对话逻辑。触发词:Discord 机器人、斜杠命令、Discord.js、Pycord、gateway intents、分片

How to use this skill

Skill file

何时使用

需要从零搭建或重构生产级 Discord 机器人,涉及:网关意图(intents)取舍、斜杠命令注册、交互组件(按钮/下拉/模态框)、3 秒响应窗口、限流退避、2500+ 服务器分片时使用。两套技术栈:Discord.js v14(JS/TS) 与 Pycord(Python)。

核心原则:

不该用:搭建 Slack/Telegram 等其它平台机器人(→ 其它技能);只想做 LLM 对话逻辑而非机器人架构;做语音频道功能、支付订阅、数据库持久化等本技能不覆盖的子领域(见“互见”委派)。本技能产物不替代环境内的实测与专家评审。

步骤

  1. 初始化客户端,只声明最小意图(默认 Guilds)。
  2. 拆分目录:commands/(命令) + events/(事件) + 独立的 deploy-commands.js 注册脚本(JS);或 main.py + cogs/(Python)。
  3. 写斜杠命令:SlashCommandBuilder(JS) / @bot.slash_command(Py)。
  4. 注册命令:开发用 guild 命令(秒级生效),生产用 global 命令(最长 1 小时传播)。绝不在 on_ready/启动时同步。
  5. 慢操作先 defer:超过 3 秒的逻辑前先 deferReply()/ctx.defer(),拿到 15 分钟窗口后 editReply/followup。
  6. 加交互组件:按钮、下拉、模态框;模态框必须是首个响应。
  7. 限流与分片:批量操作走限流队列;接近 2500 服务器接入分片。

指令

示例

斜杠命令 + 慢操作 defer(Discord.js v14):

// src/index.js —— 最小意图
const { Client, GatewayIntentBits } = require('discord.js');
require('dotenv').config();
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.login(process.env.DISCORD_TOKEN);
// 命令:慢操作必须先 defer(3 秒内)
async execute(interaction) {
  await interaction.deferReply();          // 立即确认,换 15 分钟窗口
  const result = await slowDatabaseQuery();
  await interaction.editReply(`结果: ${result}`);
}
// deploy-commands.js —— 手动跑,开发用 guild(即时),生产用 global
const rest = new REST().setToken(process.env.DISCORD_TOKEN);
await rest.put(  // 开发: applicationGuildCommands(CLIENT_ID, GUILD_ID)
  Routes.applicationCommands(process.env.CLIENT_ID),
  { body: commands }
);

Pycord 等价写法:

intents = discord.Intents.default()       # 仅默认意图,按需开特权意图
bot = commands.Bot(command_prefix="!", intents=intents)

@bot.slash_command(name="slow-task")
async def slow_task(ctx: discord.ApplicationContext):
    await ctx.defer()                      # 立即确认
    result = await slow_database_query()
    await ctx.followup.send(f"结果: {result}")

bot.run(os.environ["DISCORD_TOKEN"])

模态框必须是首个响应(不能先 defer/reply):

async execute(interaction) {
  // 正确:直接 showModal;错误:deferReply() 后再 showModal 会报“已确认”
  await interaction.showModal(modal);
}

注意事项

互见

按需委派到其它技能:AI 对话机器人 → llm-architect;Slack 跨平台 → slack-bot-builder;语音频道 → voice-agents;数据持久化(用户/配置/审核日志) → postgres-wizard;事件触发工作流 → workflow-automation;大规模高可用/监控 → devops;付费订阅功能 → stripe-specialist。


采编自 sickn33/antigravity-awesome-skills(原条目源 vibeship-spawner-skills,Apache 2.0;本仓库 MIT)。

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.