0

I'm following a tutorial on YouTube: how on how to code a Discord bot

(I'm very new to coding and wanted to start somewhere, also I needed a bot).

The code was working fine until I started adding some more commands such as -play and -leave. After that the bot doesn't responds to any commands.

I've tried changing the prefixes, starting from scratch, and just copy-pasting his code to mine. The bot turns online, but its almost like the code that makes him respond isn't there.

Here's my code:

const Discord = require('discord.js');
const client = new Discord.Client({ intents: [] })

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('SaltSounds Is Online!');
});

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


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

if(command === 'ping'){
    message.channel.send('pong!')
    }
});

client.login('my token');
F. Hauri - Give Up GitHub
  • 64,122
  • 17
  • 116
  • 137
MrPureSalt
  • 3
  • 1
  • 2
  • What version of discord.js are you using? – MrMythical Sep 14 '21 at 21:01
  • Your client intents are empty, have you tried added intents to recive guild messages – Elitezen Sep 14 '21 at 21:01
  • 1
    @MrMythical i'm using Version 13.1.0 – MrPureSalt Sep 14 '21 at 21:07
  • @Elitezen I dont know what intents really are, do you have something i could put in them? Also yes i have but not with that line of code. – MrPureSalt Sep 14 '21 at 21:08
  • 2
    Does this answer your question? "[message event listener not working properly](https://stackoverflow.com/q/64394000/90527)", "[Having trouble sending a message to a channel with Discord.js](https://stackoverflow.com/q/68795635/90527)", "[Discord bot is not replying to messages](https://stackoverflow.com/q/68804831/90527)". – outis Oct 30 '21 at 22:23

1 Answers1

0

You need these two intents to receive messages: GUILDS, GUILD_MESSAGES. You can implement it like this

const Discord = require('discord.js');
const { Intents } = Discord;
const client = new Discord.Client({ 
  intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] 
})
MrMythical
  • 8,908
  • 2
  • 17
  • 45