nomadsky
nomadsky

Reputation: 17

Why doesn't my discordjs bot code work anymore?

I decided to create a new bot so I copied the old simplified code I had and installed everything I needed but i'm getting an error for some reason while my older bot with basically the same code works.

require('dotenv').config();   

const Discord = require('discord.js');
const axios   = require('axios'); 
const client = new Discord.Client();
const prefix = 's.';
const fs = require('fs');

// const { join } = require('path');

client.commands = new Discord.Collection();

const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith(".js"));
for(const file of commandFiles) {
    const command = require(`./commands/${file}`);
    client.commands.set(command.name, command);
}

client.on("ready", () => {
    console.log(`${client.user.tag} : Online`);
});

client.on("message", async (message) => {

    if(!message.content.startsWith(prefix) || message.author.bot) return;

    const args = message.content.slice(prefix.length).split(/ +/);
    const command = args.shift().toLowerCase();

    //normal command table
    if(command == 'ping') {
        client.commands.get('ping')
        .run(message, args);
    } else if (command == 'help') {
        client.commands.get('help')
        .run(message, args);
    } else if (command == 'muta') {
        client.commands.get('muta')
        .run(message, args);
    }
});

client.login(process.env.BOT_TOKEN);           

The error i'm getting is: [Symbol(code)]: 'CLIENT_MISSING_INTENTS' and I'm guessing

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

is causing the error since it doesn't say that "Discord" is an alias module for "discord.js". If you have any idea on why, i'd appreciate the help!

Upvotes: 0

Views: 626

Answers (2)

hayeselnut
hayeselnut

Reputation: 86

When you installed your dependencies you probably upgraded to v13 of Discord.js, which now requires a list of Intents when initialising your Discord Client.

Since your bot reads and responds to messages, it will need the following intents:

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

You can read more about how discord.js uses intents here

Upvotes: 1

WoJo
WoJo

Reputation: 516

You tried importing a discord bot that was made in a version before v13. v13 is the latest discordjs version and it requires you to add certain intents to Client.

Example:

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

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

To see what intents your bot needs, you can look at the entire list of intents available here.

Upvotes: 2

Related Questions