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

Discord机器人无法运行排查求助(疑似Intents问题)

Discord机器人无法运行的问题排查与修复

1. 致命拼写错误:事件名称写错

你的代码里监听消息的事件名是messagCreate,少了一个字母e,正确的事件名应该是messageCreate。这个错误会导致机器人完全无法监听消息事件,自然无法响应任何前缀命令。

2. 确认Intents的后台配置

虽然代码中已经声明了必要的Intents(GatewayIntentBits.Guilds、GatewayIntentBits.GuildMessages、GatewayIntentBits.MessageContent),但MessageContent属于特权意图,必须在Discord开发者平台的机器人设置页面手动开启:

  • 进入Discord开发者门户,打开你的应用
  • 切换到「Bot」标签页
  • 在「Privileged Gateway Intents」区域,开启「Message Content Intent」

3. 机器人Token未填写

client.login("")中的参数为空,你需要填入从Discord开发者平台获取的机器人Token才能让机器人正常登录。

修正后的完整代码

const {
  Client,
  GatewayIntentBits,
  EmbedBuilder,
  PermissionsBitfield,
  Permissions,
} = require("discord.js");

const prefix = ">";

const client = new Client({
  intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildMessages,
    GatewayIntentBits.MessageContent,
  ],
});

// 监听消息事件(已修正拼写)
client.on("messageCreate", (message) => {
  if (!message.content.startsWith(prefix) || message.author.bot) return;

  const args = message.content.slice(prefix.length).split(/ +/);
  const command = args.shift().toLowerCase();

  //test Command
  if (command === "test") {
    message.channel.send("Bot is working!");
  }
});

client.once("ready", () => {
  console.log("Bot Ready");
});

// 填入你的机器人Token
client.login("你的机器人Token");

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.16 02:01:17