I am building a Discord bot where everything is configured properly but I am having a problem with fetching the message data. I am aware of the newest version of discord.js, thus I am using messageCreate
.
I've added some console logs in order to track the errors, and seems that message sent to the server where the bot is operating - is not recognized at all by the JS script:
client.on('messageCreate', async message => {
console.log(`Received message from ${message.author.tag} in ${message.guild ? message.guild.name : 'DM'}:`);
console.log(`Content: ${message.content}`);
console.log(`Embeds: ${JSON.stringify(message.embeds)}`);
console.log(`Attachments: ${JSON.stringify(message.attachments)}`);
// Ignore messages from bots
if (message.author.bot) return;
if (message.content === '!bitcoin') {
try {
const price = await getBitcoinPrice();
message.channel.send(`The current price of Bitcoin is $${price}`);
} catch (error) {
if (error instanceof FetchError) {
message.channel.send(error.message);
} else {
message.channel.send('An unexpected error occurred.');
}
}
}
}
The output is clearly pointing that message data is empty:
Logged in as [bot-name]
Received message from [user] in [server-name]:
Content:
Embeds: []
Attachments: []
Any idea why this is the case?