use*_*601 22 javascript node.js discord discord.js
在discord v14中,我尝试使用该messageCreate事件,但是,当用户在discord中键入消息后,message.content没有任何数据,如下所示:
Message {
channelId: '998889338475655188',
guildId: '948995127148425246',
id: '998925735668498433',
createdTimestamp: 1658232854526,
type: 0,
system: false,
content: '',
author: User
Run Code Online (Sandbox Code Playgroud)
我尝试四处搜索,但找不到任何解决该问题的方法,我使用的与不和谐相关的代码是:
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)
Run Code Online (Sandbox Code Playgroud)
有谁知道新更新出了什么问题或需要更改什么?
Zso*_*ros 59
确保在开发人员门户上启用消息内容意图并将GatewayIntentBits.MessageContent枚举添加到数组中intents。
应用程序 \xe2\x86\xa6 设置 \xe2\x86\xa6 机器人 \xe2\x86\xa6 特权网关意图
\n\n您还需要添加意图MessageContent:
const { Client, GatewayIntentBits, Partials } = require(\'discord.js\');\nconst client = new Client({\n intents: [\n GatewayIntentBits.DirectMessages,\n GatewayIntentBits.Guilds,\n GatewayIntentBits.GuildBans,\n GatewayIntentBits.GuildMessages,\n GatewayIntentBits.MessageContent,\n ],\n partials: [Partials.Channel],\n});\nRun Code Online (Sandbox Code Playgroud)\n并确保使用messageCreate事件而不是message:
client.on(\'messageCreate\', (message) => {});\nRun Code Online (Sandbox Code Playgroud)\n如果您使用的是discord.js v13,则需要在开发者门户上启用消息内容意图,如果您的机器人使用Discord API v10,则需要将标志添加到您的MESSAGE_CONTENT意图中:
const { Client, Intents } = require(\'discord.js\');\nconst client = new Client({\n intents: [\n Intents.FLAGS.GUILDS,\n Intents.FLAGS.GUILD_MESSAGES,\n Intents.FLAGS.MESSAGE_CONTENT,\n ],\n});\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
33686 次 |
| 最近记录: |