Search code examples
javascriptdiscorddiscord.jsrequirejsrequire

Trying to make a discord but I keep getting the error "required is not defined"


I'm really new at this and I'm trying to get the bot to come online but no matter what I do the error message comes up, I also downloaded requirejs but it doesn't seem to be working. basically, I have no idea what I'm doing and need help.

const {Clients, Intents} = require(discord.js);
const TOKEN = '************************************************'
const client = new Client({
    intents: [
        Inents.FLAGS.GUILDS,
        Intents.FLags.GUILD_MESSAGES,
    ]
});




client.once('ready', () => {
    console.log('Logged in as ${client.user.tag}')
});
client.login(TOKEN);

Solution

  • A couple things. Don't give out your token on public websites. Discord has probably dmed you saying you gave out your token here, but still. I'd recommend creating a .env file with the 'dotenv' package (if you know what that is.) just to keep your token private.

    On your 5th line, Intents has a typo, it says Inents. So, make sure that's fixed, and same with the 6th line. It should be FLAGS not FLags

    The reason "require" isn't defined is because you need to put discord.js in quotations like this.

    const {Clients, Intents} = require('discord.js');

    If you have any other errors, feel free to reply with it. Have a great day.