Issue with Message Logger

Hey, for some reason this code always sets the message recorded in the embed to 'No content' any idea why?
client.on('messageCreate', async (message) => {
if (message.author.bot) return;

const logChannel = await client.channels.fetch('1337561410628223089');
if (!logChannel) return console.error('Log channel not found.');

let messageContent = message.content.trim();


if (message.attachments.size > 0) {
const attachmentLinks = message.attachments.map(a => `[File](${a.url})`).join(', ');
messageContent += `\nšŸ“Ž **Attachments:** ${attachmentLinks}`;
}


if (message.stickers.size > 0) {
const stickerNames = message.stickers.map(sticker => sticker.name).join(', ');
messageContent += `\nšŸƒ **Stickers:** ${stickerNames}`;
}


if (message.embeds.length > 0) {
messageContent += `\nšŸ”— **Embeds:** (Embed content detected)`;
}

if (!messageContent.trim()) {
messageContent = '*No content*';
}

const embed = new EmbedBuilder()
.setTitle('Message Sent')
.addFields(
{ name: 'Message Content', value: messageContent },
{ name: 'Sent By', value: `<@${message.author.id}>`, inline: true },
{ name: 'Sent In', value: `<#${message.channel.id}>`, inline: true }
)
.setFooter({ text: `Date: ${new Date().toLocaleString()}` })
.setColor(0x3498db);

logChannel.send({ embeds: [embed] });
});
client.on('messageCreate', async (message) => {
if (message.author.bot) return;

const logChannel = await client.channels.fetch('1337561410628223089');
if (!logChannel) return console.error('Log channel not found.');

let messageContent = message.content.trim();


if (message.attachments.size > 0) {
const attachmentLinks = message.attachments.map(a => `[File](${a.url})`).join(', ');
messageContent += `\nšŸ“Ž **Attachments:** ${attachmentLinks}`;
}


if (message.stickers.size > 0) {
const stickerNames = message.stickers.map(sticker => sticker.name).join(', ');
messageContent += `\nšŸƒ **Stickers:** ${stickerNames}`;
}


if (message.embeds.length > 0) {
messageContent += `\nšŸ”— **Embeds:** (Embed content detected)`;
}

if (!messageContent.trim()) {
messageContent = '*No content*';
}

const embed = new EmbedBuilder()
.setTitle('Message Sent')
.addFields(
{ name: 'Message Content', value: messageContent },
{ name: 'Sent By', value: `<@${message.author.id}>`, inline: true },
{ name: 'Sent In', value: `<#${message.channel.id}>`, inline: true }
)
.setFooter({ text: `Date: ${new Date().toLocaleString()}` })
.setColor(0x3498db);

logChannel.send({ embeds: [embed] });
});
No description
7 Replies
d.js toolkit
d.js toolkitā€¢2w ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
d.js docs
d.js docsā€¢2w ago
If you aren't getting content, embeds or attachments of a message, make sure you have the MessageContent intent enabled in the Developer Portal and provide it to your client:
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent]
});
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent]
});
Unknown User
Unknown Userā€¢2w ago
Message Not Public
Sign In & Join Server To View
br1t
br1tOPā€¢2w ago
then what would be an alternative? Only logging from certain channels?
Unknown User
Unknown Userā€¢2w ago
Message Not Public
Sign In & Join Server To View
br1t
br1tOPā€¢2w ago
also this fixed it ty moderation
Unknown User
Unknown Userā€¢2w ago
Message Not Public
Sign In & Join Server To View

Did you find this page helpful?