Can't access Message.content

My bot (it is in one guild and all intents enable in ddev panel) can't acess message content after message is create Code
import {
Attachment, EmbedBuilder, GuildMember, Message, TextChannel, ThreadAutoArchiveDuration,
} from 'discord.js';
import { Settings } from '@config/settings';
import { container } from 'tsyringe';
import { BotLogger } from '@app/core/BotLogger';

export async function createSuggestion(member: GuildMember, suggestion: string, attachment? :Attachment): Promise<void | Message> {
const logger: BotLogger = container.resolve(BotLogger);
const nickname: string = member.nickname ? `(aka ${member.nickname})` : '';
const embed: EmbedBuilder = new EmbedBuilder({
title: `Suggestion de ${member.user.tag} ${nickname}`,
color: 0xed4245,
description: suggestion,
footer: { text: `${member.user.id}` },
image: { url: attachment && attachment.contentType === 'image' ? attachment.url : undefined },
});

console.log(`debug : ${suggestion.substring(0, 80)}`); // debug : lorem ipsum
const channel: TextChannel = member.guild.channels.resolve(Settings.channels.suggestion) as TextChannel;
try {
const message: Message = await channel.send({ embeds: [embed] });
console.log(`debug 2 : ${message.content}`); // debug 2 :
await message.react('👍');
await message.react('👎');
await message.startThread({
name: 'Test : ' + message.content.substring(0, 70),
reason: `Suggestion de ${member.user.tag}`,
autoArchiveDuration: ThreadAutoArchiveDuration.OneWeek,
});
return await Promise.resolve();
} catch (e: unknown) {
logger.error('Impossible de faire une suggestion', e);
return Promise.reject();
}
}
import {
Attachment, EmbedBuilder, GuildMember, Message, TextChannel, ThreadAutoArchiveDuration,
} from 'discord.js';
import { Settings } from '@config/settings';
import { container } from 'tsyringe';
import { BotLogger } from '@app/core/BotLogger';

export async function createSuggestion(member: GuildMember, suggestion: string, attachment? :Attachment): Promise<void | Message> {
const logger: BotLogger = container.resolve(BotLogger);
const nickname: string = member.nickname ? `(aka ${member.nickname})` : '';
const embed: EmbedBuilder = new EmbedBuilder({
title: `Suggestion de ${member.user.tag} ${nickname}`,
color: 0xed4245,
description: suggestion,
footer: { text: `${member.user.id}` },
image: { url: attachment && attachment.contentType === 'image' ? attachment.url : undefined },
});

console.log(`debug : ${suggestion.substring(0, 80)}`); // debug : lorem ipsum
const channel: TextChannel = member.guild.channels.resolve(Settings.channels.suggestion) as TextChannel;
try {
const message: Message = await channel.send({ embeds: [embed] });
console.log(`debug 2 : ${message.content}`); // debug 2 :
await message.react('👍');
await message.react('👎');
await message.startThread({
name: 'Test : ' + message.content.substring(0, 70),
reason: `Suggestion de ${member.user.tag}`,
autoArchiveDuration: ThreadAutoArchiveDuration.OneWeek,
});
return await Promise.resolve();
} catch (e: unknown) {
logger.error('Impossible de faire une suggestion', e);
return Promise.reject();
}
}
call in a messageCreate event
5 Replies
d.js docs
d.js docs3y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers. Tag suggestion for @weeskybdw: 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]
});
WeeskyBDW
WeeskyBDWOP3y ago
i have
WeeskyBDW
WeeskyBDWOP3y ago
i mean my bot have all intents
Idris
Idris3y ago
and in the ClientOptions too?
WeeskyBDW
WeeskyBDWOP3y ago
yes
export const client = new Client({
intents: [
IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMembers,
IntentsBitField.Flags.GuildMessageReactions,
IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.MessageContent,
],
// solution proposé par Victorique#0001, étant plus sûr que cache#first()
botGuilds: [(c: Client) => c.guilds.cache.map((guild) => guild.id)],
});
export const client = new Client({
intents: [
IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMembers,
IntentsBitField.Flags.GuildMessageReactions,
IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.MessageContent,
],
// solution proposé par Victorique#0001, étant plus sûr que cache#first()
botGuilds: [(c: Client) => c.guilds.cache.map((guild) => guild.id)],
});
(i log it below in the code) prob i missused async/await, 🤷‍♂️ ok i'm an assol i was trying to get Message#content from a Message who only have an embed Fixed, thx you
Want results from more Discord servers?
Add your server