【问题标题】:Discord.client is not a constructor - discord.js我是 discord.js 的初学者,我遇到了一些问题
【发布时间】:2022-01-11 09:35:37
【问题描述】:

我制作了一个不和谐的机器人并尝试了我在 youtube 上找到的初学者代码,这是我的代码和我的错误

代码

// Require the necessary discord.js classes
const Discord = require('discord.js');
const client = new Discord.client();
const config = require('./config.json');

client.on('ready', () => {
  console.log('the client is ready!')
})

// Login to Discord with your client's token
client.login(config.token)

错误

~/.../stuff/hazy $ node hazy.js
/storage/emulated/0/stuff/hazy/hazy.js:3
const client = new Discord.client();
               ^

TypeError: Discord.client is not a constructor
    at Object.<anonymous> (/storage/emulated/0/stuff/hazy/hazy.js:3:16)
    at Module._compile (node:internal/modules/cjs/loader:1097:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1149:10)
    at Module.load (node:internal/modules/cjs/loader:975:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:17:47

Node.js v17.2.0

【问题讨论】:

    标签: node.js npm discord discord.js termux


    【解决方案1】:

    Discord.js 提供的client 类称为Client

    客户

    客户端扩展 BaseClient

    与 Discord API,以及任何机器人的起点。

    使用new Discord.Client() 而不是new Discord.client()

    或者直接用const { Client } = require("discord.js")导入客户端,然后用new Client()实例化

    【讨论】:

      猜你喜欢
      • 2022-08-19
      • 2021-05-13
      • 1970-01-01
      • 1970-01-01
      • 2014-09-28
      • 1970-01-01
      • 1970-01-01
      • 2022-11-23
      • 1970-01-01
      相关资源
      最近更新 更多