Is it possible to edit a componentV2 message ?

import { CronJob } from 'cron';
import { Client, ContainerBuilder, MessageFlags, TextDisplayBuilder } from 'discord.js';
// import { getLeaderboardData } from '../db/leaderboardData.ts';
import { getSettings } from '../db/settings.ts';

export async function startLeaderboardUpdater(client: Client) {
const job = new CronJob('*/5 * * * *', async () => {
const settings = await getSettings();

if (!settings?.leaderboardChannelId) {
return;
}

// const leaderboard = await getLeaderboardData(settings?.serverId);
const channel = client.channels.cache.get(settings?.leaderboardChannelId);
if (!channel || !channel.isTextBased() || !settings?.leaderboardMessageId) {
return;
}

try {
const message = await channel.messages.fetch(settings?.leaderboardMessageId);

await message.edit({
components: [
new ContainerBuilder(
new TextDisplayBuilder().setContent(`Leaderboard (Updated at <t:${Date.now()}:R>)`),
)
],
flags: [
MessageFlags.IsComponentsV2
]
});
} catch {
// Ignore errors
}
});
job.start();
}

import { CronJob } from 'cron';
import { Client, ContainerBuilder, MessageFlags, TextDisplayBuilder } from 'discord.js';
// import { getLeaderboardData } from '../db/leaderboardData.ts';
import { getSettings } from '../db/settings.ts';

export async function startLeaderboardUpdater(client: Client) {
const job = new CronJob('*/5 * * * *', async () => {
const settings = await getSettings();

if (!settings?.leaderboardChannelId) {
return;
}

// const leaderboard = await getLeaderboardData(settings?.serverId);
const channel = client.channels.cache.get(settings?.leaderboardChannelId);
if (!channel || !channel.isTextBased() || !settings?.leaderboardMessageId) {
return;
}

try {
const message = await channel.messages.fetch(settings?.leaderboardMessageId);

await message.edit({
components: [
new ContainerBuilder(
new TextDisplayBuilder().setContent(`Leaderboard (Updated at <t:${Date.now()}:R>)`),
)
],
flags: [
MessageFlags.IsComponentsV2
]
});
} catch {
// Ignore errors
}
});
job.start();
}

The line with TextDisplayBuilder show this error The 'TextDisplayBuilder' type has no properties in common with the 'Partial<APIContainerComponent>' type.
6 Replies
d.js toolkit
d.js toolkit5mo ago
Amgelo
Amgelo5mo ago
ContainerBuilder takes raw container data in its constructor not a TextDisplayBuilder construct the container the same way you originally created it
Vasolix
VasolixOP5mo ago
there is my original message :
const message = await channel.send({
components: [
new ContainerBuilder()
.addTextDisplayComponents(
new TextDisplayBuilder().setContent(`Classement des utilisateurs (Mis à jour il y à <t:${Date.now() / 1000}:R>)`),
)
],
allowedMentions: {},
flags: [MessageFlags.IsComponentsV2],
});
const message = await channel.send({
components: [
new ContainerBuilder()
.addTextDisplayComponents(
new TextDisplayBuilder().setContent(`Classement des utilisateurs (Mis à jour il y à <t:${Date.now() / 1000}:R>)`),
)
],
allowedMentions: {},
flags: [MessageFlags.IsComponentsV2],
});
Amgelo
Amgelo5mo ago
right, notice how you're using addTextDisplayComponents you're not passing the TextDisplayBuilder to the ContainerBuilder constructor do the same thing here
Vasolix
VasolixOP5mo ago
Oh thx
d.js toolkit
d.js toolkit5mo ago
The thread owner has marked this issue as solved.

Did you find this page helpful?