Reputation: 313
The other day, some quirck made the discord bot I made for my personal server several years ago, stop working. So now I have to build it from the ground up. Even following the setup from the Discord tutorial, I can't get basic functions to work anymore. Here's what I'm struggling with right now:
// Require the necessary discord.js classes
const { Client, GatewayIntentBits } = require('discord.js');
const { token } = require('./config.json');
// Create a new client instance
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
// When the client is ready, run this code (only once)
client.once('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
// Reply to a user who mentions the bot
client.on('messageCreate', message => {
console.log(`I see a message!`);
if (message.mentions.has(client.user)) {
console.log(`I see a mention!`);
message.channel.send(`Working on it!`);
}
});
// Login to Discord with your client's token
client.login(token);
Neither of the console.log commands within the messageCreate event trigger, so it seems that for some reason, my bot isn't even watching for that event, but I cannot find anywhere online that will tell me why, especially since this exact method used to work for my old bot. (The console.log that triggers when the bot logs in works just fine.)
Upvotes: 1
Views: 1258
Reputation: 106
Ensure you have all of the required intents, and that they are also enabled in the Discord developer portal under the bot section.
Based on what I can tell, you need the GuildMessages and MessageContent intents. So fix your client initialization to include them.
const client = new Client({ intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
]});
(On another note, for testing, I recommend putting as many intents as possible, as I have had many problems that were just me forgetting to enable intents)
Upvotes: 2