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

Discord.js v14中messageCreate事件下message.content为空问题求助

Discord.js v14 message.content为空的解决方案

问题根源是缺少读取消息内容的权限。Discord平台的隐私政策更新后,读取消息内容需要单独开启MessageContent权限,该权限需同时在代码中声明和开发者后台启用。

修复步骤

1. 更新代码添加权限

在客户端初始化的intents数组中加入GatewayIntentBits.MessageContent:

import { Client, GatewayIntentBits, Partials } from "discord.js";

const bot = new Client({
  intents: [
    GatewayIntentBits.DirectMessages,
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildBans,
    GatewayIntentBits.GuildMessages,
    GatewayIntentBits.MessageContent // 新增读取消息内容的权限
  ],
  partials: [Partials.Channel]
});

bot.on('messageCreate', async (message) => {
  console.log(message);
});

bot.login(process.env.token1)

2. 在Discord开发者平台开启权限

  • 登录Discord开发者平台,找到你的应用
  • 进入Bot页面
  • 在Privileged Gateway Intents板块,开启Message Content Intent开关
  • 保存设置后重启机器人

完成以上操作后,message.content就能正常获取用户发送的消息内容。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.26 05:54:16