Paswa
Paswa

Reputation: 3

Error "const Discord = require(discord.js) ^ ReferenceError: discord is not defined"

Hi there so i have a weird error that i get that says this "const Discord = require(discord.js) ^ ReferenceError: discord is not defined" here is the code i have written is there a error that i put in there?

const Discord = require(discord.js)
const Client = new Discord.Client
const prefix = "/";
Client.on('ready', ()=>{
    console.log('Bot is online.');
})
Client.on('message', (Message)=>{
    if(!Message.content.startsWith(prefix)) return;
    if(Message.content.startsWith(prefix + "hello")){
        Message.channel.send("Hello.")
    }
})
Client.login("<Token Here>");

Upvotes: 0

Views: 8731

Answers (6)

ImFantasy
ImFantasy

Reputation: 1

That's right:

const Discord = require("discord.js");
const Client = new Discord.Client
const prefix = "/";
Client.on('ready', () => {
    console.log('Bot is online.')
});

Client.on('message', (Message) => {
    if(!Message.content.startsWith(prefix)) return;
    if(Message.content.startsWith(prefix + "hello")){
        Message.channel.send("Hello.")
    }
});

Client.login("<Token Here>");

Upvotes: -1

Balaram Ghosh
Balaram Ghosh

Reputation: 1

Wrap module name using quotations " or ' .

Use the command below :

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

Upvotes: 0

Picsou
Picsou

Reputation: 24

You forgot the " or ' in:

const Discord = require(discord.js)

so try :

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

Upvotes: 1

mrdenizlp
mrdenizlp

Reputation: 128

When defining something in const syntax, you must always use " or '.

Upvotes: 2

Syntle
Syntle

Reputation: 5174

When importing/requiring anything you have to pass it as a string. You essentially tried to pass it as a variable.

const Discord = require('discord.js')

Upvotes: 0

rishi
rishi

Reputation: 2554

Try this:

const Discord = require('discord.js')

Upvotes: 0

Related Questions