首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Discord.client不是构造函数- discord.js

Discord.client不是构造函数- discord.js
EN

Stack Overflow用户
提问于 2021-12-06 04:58:19
回答 1查看 342关注 0票数 -1

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

文件index.js

代码语言:javascript
复制
// 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)

错误

代码语言:javascript
复制
~/.../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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-12-06 08:39:16

客户端类由Discord.js提供,称为Client

客户端 客户端扩展BaseClient 与不和谐API交互的主要中心,以及任何bot的起点。

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

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

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70241045

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档