【问题标题】:message.content doesn't have any value in Discord.jsmessage.content 在 Discord.js 中没有任何价值
【发布时间】:2022-11-14 06:07:13
【问题描述】:

在 discord v14 中,我尝试使用 messageCreate 事件,但是,在用户在 discord 中键入消息后,message.content 没有任何数据,如下所示:

Message {
  channelId: '998889338475655188',
  guildId: '948995127148425246',
  id: '998925735668498433',
  createdTimestamp: 1658232854526,
  type: 0,
  system: false,
  content: '',
  author: User 

我已经尝试四处搜索,但找不到任何解决该问题的方法,我使用的与不和谐相关的代码是:

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

const bot = new Client({
  'intents': [
    GatewayIntentBits.DirectMessages,
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildBans,
    GatewayIntentBits.GuildMessages
  ],
  'partials': [Partials.Channel]
});

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

bot.login(process.env.token1)

有谁知道新更新出了什么问题或需要改变什么?

【问题讨论】:

  • 确认您设置了公会消息意图并且内容/味精不是部分的?
  • @0xLogN 如果消息是从自身发送的,它将起作用。例如我做了:bot.on('ready', () => { console.log(`The Discord bot ${bot.user.username} is ready!`); bot.channels.cache.get(outputChannelID).send(`The Discord bot ${bot.user.username} is ready!`); }); 在来自'messageCreate' async (message) 的console.log 中我得到content: The Discord bot bot.user.username is ready! 但不适用于用户。

标签: javascript node.js discord discord.js


【解决方案1】:

确保在 developer portal 上启用消息内容意图,并将 GatewayIntentBits.MessageContent 枚举添加到 intents 数组。

应用程序↦设置↦机器人↦特权网关意图

您还需要添加 MessageContent 意图:

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

如果您使用的是 discord.js v13,则需要在您的开发者门户上启用消息内容意图,如果您的机器人使用 Discord API v10,您需要将 MESSAGE_CONTENT 标志添加到您的意图:

const client = new Client({
  intents: [
    Intents.FLAGS.GUILDS,
    Intents.FLAGS.GUILD_MESSAGES,
    Intents.FLAGS.MESSAGE_CONTENT,
  ],
});

【讨论】:

  • Discordjs v14 迁移并没有说要添加 GatewayIntentBits.MessageContent 他们忘记添加它或smth
  • @It'sMateo20 — 这是 Discord 结束时权限要求的变化。我认为 discord.js 已经支持它一段时间了。
猜你喜欢
  • 2020-07-08
  • 2021-03-29
  • 2019-07-14
  • 2022-07-31
  • 2013-11-18
  • 1970-01-01
  • 1970-01-01
  • 2021-11-06
  • 2022-07-29
相关资源
最近更新 更多