You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Discord Guild Commands注册失败:上下文菜单覆盖且上传Pending

解决Guild命令被上下文菜单覆盖及上传请求Pending问题

1. 终止Pending请求并清理无效命令

  • 立即重启机器人进程,停止所有未完成的命令同步任务
  • 通过Discord开发者门户手动清理目标服务器的命令:
    • 进入你的机器人应用页面,切换到Commands -> Guild Commands,选择目标服务器,删除所有失效命令
    • 重新生成带applications.commands权限的邀请链接,重新邀请机器人到服务器(刷新命令授权缓存)

2. 修复命令处理器的导出逻辑

核心问题是你未同时导出上下文菜单与Guild命令,导致同步时仅上传上下文菜单覆盖原有命令。需确保处理器同时收集两种命令类型并合并上传:

修正后的命令处理器示例(discord.js v14+)

const { REST, Routes } = require('discord.js');
const fs = require('fs');
const path = require('path');

module.exports = async (client) => {
  const slashCommands = [];
  const contextMenuCommands = [];

  // 加载Slash命令
  const cmdDir = path.join(__dirname, 'commands');
  const cmdFiles = fs.readdirSync(cmdDir).filter(f => f.endsWith('.js'));
  for (const file of cmdFiles) {
    const cmd = require(path.join(cmdDir, file));
    slashCommands.push(cmd.data.toJSON());
    client.commands.set(cmd.data.name, cmd);
  }

  // 加载上下文菜单
  const menuDir = path.join(__dirname, 'contextMenus');
  const menuFiles = fs.readdirSync(menuDir).filter(f => f.endsWith('.js'));
  for (const file of menuFiles) {
    const menu = require(path.join(menuDir, file));
    contextMenuCommands.push(menu.data.toJSON());
    client.contextMenus.set(menu.data.name, menu);
  }

  // 合并所有命令类型,统一上传
  const allCommands = [...slashCommands, ...contextMenuCommands];

  const rest = new REST({ version: '10' }).setToken(process.env.BOT_TOKEN);

  try {
    console.log(`同步 ${allCommands.length} 个命令(含上下文菜单)到目标服务器`);
    await rest.put(
      Routes.applicationGuildCommands(process.env.CLIENT_ID, process.env.TARGET_GUILD_ID),
      { body: allCommands }
    );
    console.log("命令同步完成");
  } catch (err) {
    console.error("同步失败:", err);
  }
};

3. 验证与缓存刷新

  • 同步完成后,在服务器输入/,检查Guild命令和上下文菜单是否正常显示
  • 若仍不显示,开启Discord开发者模式,右键服务器复制ID,在开发者门户的Guild Commands中确认命令是否已上传
  • 等待15-30分钟,Discord的命令缓存会自动刷新

4. 处理顽固Pending请求

如果上述操作后请求仍处于Pending状态,执行强制清理后重新上传:

// 先清空服务器所有命令
await rest.put(
  Routes.applicationGuildCommands(process.env.CLIENT_ID, process.env.TARGET_GUILD_ID),
  { body: [] }
);
// 重新上传合并后的命令
await rest.put(
  Routes.applicationGuildCommands(process.env.CLIENT_ID, process.env.TARGET_GUILD_ID),
  { body: allCommands }
);

内容的提问来源于stack exchange,提问作者Black Wither

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 04:35:23