"discord.client is not a constructor"

So I am trying to make a discord bot, which would be the first bot I made. However, I keep getting an error saying “discord.client is not a constructor”. Here is my code and the error
My code for my Passport Bot
const Discord = require(‘discord.js’);

const client = new Discord.client();

client.once('ready',()=> {

    console.log('Passport bot is passporting')

});

client.login('AuthToken');

The Error I get when I use the “node .” or “node main.js” commands
const client = new Discord.client();
^

TypeError: Discord.client is not a constructor
    at Object.<anonymous> (C:\Users\Owner\Desktop\DiscordBot\main.js:3:16)
    at Module._compile (internal/modules/cjs/loader.js:1201:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1221:10)
    at Module.load (internal/modules/cjs/loader.js:1050:32)
    at Function.Module._load (internal/modules/cjs/loader.js:938:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47

Any and all help would be greatly appreciated! Thank you!

1 Like

There’s a snippet of code from discord.js’s website that says:

const Discord = require('discord.js');
const client = new Discord.Client();

And you’ve shown your code to say:

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

const client = new Discord.client();

That difference in the capitalization of .Client is subtle, but significant in JavaScript. Property names are case sensitive.

Because of that, Discord.client and Discord.Client refer to two different values. The .Client is indeed a constructor, as documented. The .client, as far as I know, isn’t even defined. If that’s true, then accessing it returns the special undefined value, which isn’t a constructor.

3 Likes

Thats coding for you, even a single upcase letter can get you an error.

2 Likes

Ah yes. A single letter my favorite.
Thanks though!

I made an account just to thank you, you are such a hero and thank you so much haha. I spent around, say, 20-30 minutes rewriting the code to see if that would fix anything, and ended up remaking the entire bot about 3 times. Still, every time I failed. I can’t thank you enough!

2 Likes

Hi. Me too I have a problem. I debutant.
I have the same error but I don’t see where I fail

const Discord = require(‘discord.js’);

Client.log(‘token removed’);

const client = new Discord.Client();

Client.once(‘ready’,() => {

console.log('Ready !');

});

Client.on(‘message’, (message) => {

if (message.content === ‘!ping’) {

  message.channel.send('Pong.');

}

});

And the error message

TypeError: Discord.client is not a constructor
at Object. (C:\Users\User\Documents\Quentinbot\index.js:3:16)
at Module._compile (node:internal/modules/cjs/loader:1108:14)
at Function.Module._load (node:internal/modules/cjs/loader:813:14)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
at node:internal/main/run_main_module:17:47

Um. I don’t recommend leaking your token.

Hi @Quentin_Gales
You need to change Client.log to Client.login and put that login line below the new client line. I have also flagged your post due to the fact you leaked your token. I recommend you refresh the token via the Discord Application Portal
Hope this helps :slight_smile:

2 Likes

I believe @tasha just removed the token, but for the future, don’t share tokens :slight_smile:

I actually reset it for him just in case.

hi I’m having trouble with my code please help

const Discord = require(‘discord.js’);
const client = new Discord.client();

client.once(‘ready’, () => {
console.log(‘Bot is online!’);
});

client.login(‘token’);

C:\Users\PC\Desktop\Bot>node .
C:\Users\PC\Desktop\Bot\index.js:3
const client = new Discord.client();
^

TypeError: Discord.client is not a constructor
at Object. (C:\Users\PC\Desktop\Bot\index.js:3:16)
←[90m at Module._compile (internal/modules/cjs/loader.js:1072:14)←[39m
←[90m at Object.Module._extensions…js (internal/modules/cjs/loader.js:1101:10)←[39m
←[90m at Module.load (internal/modules/cjs/loader.js:937:32)←[39m
←[90m at Function.Module._load (internal/modules/cjs/loader.js:778:12)←[39m
←[90m at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)←[39m
←[90m at internal/main/run_main_module.js:17:47←[39m

Hi @boby_david , welcome

The post that you’re replying to contains the answer to your question :grin:

You need to change Discord.client() to Discord.Client()

(with an uppercase ‘C’)

2 Likes

I also need help with this problem

const Discord = require(‘discord.js’)

const TOKEN = “token removed”

const client = new Discord.Client({

intents: [

    "GUILDS",

    "GUILD_MESSAGES"

]

})

client.on(“ready”, () => {

console.log(`Logged in as ${client.user.tag}`)

})

client.login(TOKEN)

i am getting discord.client is not a constructor

const { Intents } = require("discord.js");
const TOKEN = "YOUR BOT TOKEN"

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

client.on(“ready”, () => {
console.log(`Logged in as ${client.user.tag}`)
})

client.login(TOKEN)

Hope this solve your problems @Fishyy :grinning:

const Discord = require(‘discord.js’)
const client = new Discord.client()

client.on(‘ready’, () => {
console.log(${client.user.username} is online!)
})

client.login(‘token’)

i dont know what i do wrong but it says discord.client is not a constructor

Hi, the response is on the topic above. You need to use “.Client”, with an uppercase C

1 Like

I as well am having a similar issue.
const Discord = require(‘discord.js’);

const prefix = ‘#’;

const client = new Discord.Client({
allowedMentions: {
parse: [‘users’, ‘roles’],
repliedUser: true,

},
intents: [
    "GUILDS",
    "GUILD_MESSAGES",
    "GUILD_PRESENCES",
    "GUILD_MEMBERS",
    "GUILD_MESSAGE_REACTIONS",
],

});

client.on(“ready”, () => {
console.log(“bot is online.”)

})

client.login(“TOKEN KEY”)

TypeError: Discord.client is not a constructor
at Object. (C:\Users\fire’s pc\Desktop\Discord Bot\index.js:5:16)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Module._extensions…js (node:internal/modules/cjs/loader:1310:10)
at Module.load (node:internal/modules/cjs/loader:1119:32)
at Module._load (node:internal/modules/cjs/loader:960:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:23:47

Node.js v18.17.0

that error messages seems out of sync with the code

yea i have no clue on what is wrong. I followed of what someone put and it should work but it didnt.

are you sure you saved and/or are in the right directory?

yes i am sure.

can you edit line 5 intentionally to misspell Discord and see if the error message picks that up?

if it does, then something sneaky is going on