'Discord.client is not a constructor - discord.js
i made a discord bot and tried a beginner code i found on youtube, this is my code and my errors
index.js
// 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)
errors
~/.../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
Solution 1:[1]
The client class provided by Discord.js is called Client.
Client
Client extends BaseClient
The main hub for interacting with the Discord API, and the starting point for any bot.
Use new Discord.Client()
instead of new Discord.client()
.
Or directly import the client using const { Client } = require("discord.js")
and then instantiate with new Client()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |