【问题标题】:How can I upgrade to Discord.js V13?如何升级到 Discord.js V13?
【发布时间】:2021-09-18 04:09:26
【问题描述】:

我正在使用 Discord.js V13,当我尝试运行机器人时,我每次都会收到此错误。

主文件:

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

const client = new Discord.Client({ 
  partials: ["CHANNEL","MESSAGE","REACTION"],
  intents: [Intents.ALL] 
});

错误:

const client = new Discord.Client({ 
                           ^

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

这里的解决方案是我不能从自身解构库,我的错误是我只需要放置我的机器人需要的意图。

我的解决方案:

const Discord = require('discord.js'); 

const client = new Discord.Client({ 
  partials: ["CHANNEL","MESSAGE","REACTION"],
  intents: [
    Discord.Intents.FLAGS.GUILDS,                // <--line 5 here
    Discord.Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
    Discord.Intents.FLAGS.GUILD_MESSAGES,
    Discord.Intents.FLAGS.GUILD_INVITES,
    Discord.Intents.FLAGS.GUILD_MEMBERS,
    Discord.Intents.FLAGS.GUILD_PRESENCES
  ]               
});

【问题讨论】:

  • 你检查过the docs吗?它有一个让客户就位的例子。

标签: javascript node.js discord.js


【解决方案1】:

你不能从自身解构图书馆。

要么解构客户端:

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

const client = new Client(...);
// ...

或者完全利用库:

const Discord = require('discord.js');

const client = new Discord.Client(...);
// ...

【讨论】:

    猜你喜欢
    • 2021-12-01
    • 2022-07-19
    • 1970-01-01
    • 2022-01-05
    • 2021-11-09
    • 2022-01-06
    • 1970-01-01
    • 2023-01-29
    • 2021-10-29
    相关资源
    最近更新 更多