Reputation: 150
So I am new to the world of discord bots and wanted to try myself on this new challenge. I got the foundation running after watching a few tutorials and reading a few posts but now my problem is that the bot doesn't react to anything after starting up...
const Discord = require('discord.js');
const { token } = require('./config.json');
const intents = new Discord.Intents('GUILDS', 'GUILDS_MESSAGES');
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('Ready!');
});
client.on('message', (message) => {
console.log('made it!');
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') {
client.commands.get('ping').execute(message, args);
}
});
client.login(token);
All it does is displaying: 'Ready!' in the console. After that, it doesn't react to anything anymore. Not on discord and not in the console.
Upvotes: 0
Views: 202
Reputation: 64
It might be because you set up Intents the wrong way.
Try and replace:
const Discord = require('discord.js');
const intents = new Discord.Intents('GUILDS', 'GUILDS_MESSAGES');
const client = new Discord.Client({ intents });
with:
const { Client, Intents } = require('discord.js');
const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
]
});
Also, use messageCreate
instead of message
Upvotes: 1