Reputation: 33
I tried making a discord bot..
I looked for some tutorials but my code doesn't seem to work..
I created a simple ping pong command but for some reason its not working!
Heres my bot.js code:
require('dotenv').config();
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds, 'GuildMessages'] });
client.on('ready', () => {
console.log(`Thunder bot is ready! Tag is ${client.user.tag}`);
});
client.on('message', (messageCreate) => {
if (message.content === 'ping'){
message.reply('Pong!')
}
});
client.login(process.env.TOKEN);
But the ping pong command is not working!
Upvotes: 1
Views: 7356
Reputation: 149
Following above solutions initially gave me this error:
This error was solved by having the 'message content intent' toggled on in the 'Bot' section of the developer portal:
Upvotes: 0
Reputation: 299
{ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] }
client.on('messageCreate', (message) => {
if (message.content === 'ping'){
message.reply('Pong!')
}
});
This should work:
require('dotenv').config();
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] });
client.on('ready', () => {
console.log(`Thunder bot is ready! Tag is ${client.user.tag}`);
});
client.on('messageCreate', (message) => {
if (message.content === 'ping'){
console.log("!")
message.reply('Pong!')
}
});
client.login(process.env.TOKEN);
Upvotes: 3
Reputation: 139
There are 2 reasons your bot isn't responding to you:
const client = new Client({ intents: ['Guilds', 'GuildMessages', 'MessageContent'] });
client.on('message'
... may result to a DeprecationWarningclient.on('messageCreate', (message) => {
if (message.content === 'ping'){
message.reply('Pong!')
}
});
Upvotes: 6
Reputation: 96
2 reasons this is happening;
message
instead of messageCreate
and vice versa in your client.on()
. Put this instead:client.on('messageCreate', message => {
if (message.content === 'ping'){
message.reply('Pong!')
}
});
const client = new Client({ intents: ["Guilds", "GuildMessages", "MessageContent"] });
Upvotes: 0