0

I have no experience with dc bots so I followed a yt tutorial but discord.js he used was an older version (v12) so I fixed the code for my version v14. The Bot goes online but when I type a command it won't respond. There are no errors it just goes online and gives the console message that's it. Maybe it's because of the version but I can't find any answers for this version. (Maybe it's something else as I said I've never done that before) This is my main.js:


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

const client = new Discord.Client({
    intents: [
      GatewayIntentBits.Guilds,
      GatewayIntentBits.GuildMessages,
    ]
  })

  const prefix ='!';

  const fs = require('fs');
  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.once('ready', () => {
    console.log('Bot is online!');
});


client.on('message', message =>{
  console.log("1")
    if(!message.content.startsWith(prefix) || message.author.bot) return;
    console.log("2")

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

    if(command === 'ping'){
        client.commands.get('ping').execute(message, args);
    }
});

client.login('TOKEN');

The console.log() 1 and 2 are to check if it works but it won't show in the console just the "Bot is online". Then I have a folder /commands with ping.js:

module.exports = {
    name: 'ping',
    description: "this is a ping command!",
    execute(message, args){
        message.channel.send('pong!')
    }
}
ashi
  • 11
  • 1

1 Answers1

1

You should request the message content intent. See how:

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

const client = new Discord.Client({
    intents: [
      GatewayIntentBits.Guilds,
      GatewayIntentBits.GuildMessages,
      GatewayIntentBits.MessageContent
    ]
  })

Note that you may also need to enable it in the Discord Developer Portal: enter image description here

Androz2091
  • 2,931
  • 1
  • 9
  • 26
  • When i add that it gives me an error: throw new Error(unrecoverableErrorCodeMap[error.code]); Error [DisallowedIntents]: Privileged intent provided is not enabled or whitelisted. I did enable the stuff in the Developer Portal – ashi Jul 20 '22 at 22:14
  • Yes that's what I mentioned in my message ahah, you should enable the intent at https://discord.dev – Androz2091 Jul 20 '22 at 22:25
  • oh sorry now error is gone I did enable it I guess it took some time to work haha but the Bot still doesn't respond – ashi Jul 20 '22 at 22:27
  • add console.log(message.content) – Androz2091 Jul 21 '22 at 07:19
  • Console stays empty it only gets "bot is online" – ashi Jul 21 '22 at 07:26