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!')
}
}