【问题标题】:Can't import discord intents无法导入不和谐意图
【发布时间】:2022-07-27 07:19:16
【问题描述】:

我无法导入不和谐意图 我有 discord.js 版本 13.6.0

这是我导入东西的开始

const { Client, Intents } = require('discord.js');

这是我得到错误的地方

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

错误是:

TypeError: Cannot read properties of undefined (reading 'FLAGS')

【问题讨论】:

  • 告诉我们什么错误
  • Intents.FLAGS.GUILDS, ^ TypeError: Cannot read properties of undefined (reading 'FLAGS')

标签: javascript discord.js


【解决方案1】:

不确定为什么会发生此错误,但您可以传递字符串而不是 Intents 对象,例如:

const bot = new Client({
    intents: [ "GUILDS", "GUILD_MESSAGES" ]
})

【讨论】:

  • 现在 bot.on("messageCreate", (message)... 不起作用
  • 尝试将其更改为仅消息,但现在“message.content”是未定义的对象
  • 尝试运行npm uninstall discord.js && npm i discord.js重新安装包并再次尝试Intents对象,我真的不知道这是怎么回事
  • 文本仍然是未定义的对象,但是,现在意图工作那么你知道如何修复 message.content 吗?
  • 登录 message 看看它是否被正确读取
【解决方案2】:

这目前对我有用:

import { Client, GatewayIntentBits } from 'discord.js';

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

可以在GatewayIntentBits 的文档中找到可能的意图。

【讨论】:

    【解决方案3】:

    我使用 IntentsBitField 而不是 Intents,它适用于我,这是一个示例:

    import DiscordJS,{ IntentsBitField } from 'discord.js'
    
    const client = new DiscordJS.Client({
        intents: [
            IntentsBitField.Flags.Guilds,
            IntentsBitField.Flags.GuildMessages
        ]
    })

    有关网关意图的更多信息,请查看此链接enter link description here

    【讨论】:

      猜你喜欢
      • 2020-11-05
      • 2021-05-28
      • 1970-01-01
      • 2021-08-01
      • 2020-10-17
      • 2020-11-07
      • 1970-01-01
      • 2021-05-17
      • 2021-11-03
      相关资源
      最近更新 更多