Trying to edit content of specific v2 component, what's wrong?

I'm running this code on an eval:
const { ContainerBuilder } = require('discord.js')


interaction.channel.messages.fetch('1384167099550662766').then(m => {
const comps = m.components.map(c=>new ContainerBuilder(c))

comps[1].components[0].setContent('Hello')

m.edit({components: comps})

})
const { ContainerBuilder } = require('discord.js')


interaction.channel.messages.fetch('1384167099550662766').then(m => {
const comps = m.components.map(c=>new ContainerBuilder(c))

comps[1].components[0].setContent('Hello')

m.edit({components: comps})

})
I want to edit the text of the container at index 1, but this error shows up in the console:
ValidationError > s.string()
Expected a string primitive

Received:
| undefined

at _StringValidator.handle (/home/moonlightcapital/lab-translator/node_modules/@sapphire/shapeshift/dist/cjs/index.cjs:2615:70)
at _StringValidator.parse (/home/moonlightcapital/lab-translator/node_modules/@sapphire/shapeshift/dist/cjs/index.cjs:972:90)
at TextDisplayBuilder.toJSON (/home/moonlightcapital/lab-translator/node_modules/@discordjs/builders/dist/index.js:1708:33)
at /home/moonlightcapital/lab-translator/node_modules/@discordjs/builders/dist/index.js:1870:64
at Array.map (<anonymous>)
at ContainerBuilder.toJSON (/home/moonlightcapital/lab-translator/node_modules/@discordjs/builders/dist/index.js:1870:35)
at /home/moonlightcapital/lab-translator/node_modules/discord.js/src/structures/MessagePayload.js:151:46
at Array.map (<anonymous>)
at MessagePayload.resolveBody (/home/moonlightcapital/lab-translator/node_modules/discord.js/src/structures/MessagePayload.js:150:49)
at GuildMessageManager.edit (/home/moonlightcapital/lab-translator/node_modules/discord.js/src/managers/MessageManager.js:186:8)
ValidationError > s.string()
Expected a string primitive

Received:
| undefined

at _StringValidator.handle (/home/moonlightcapital/lab-translator/node_modules/@sapphire/shapeshift/dist/cjs/index.cjs:2615:70)
at _StringValidator.parse (/home/moonlightcapital/lab-translator/node_modules/@sapphire/shapeshift/dist/cjs/index.cjs:972:90)
at TextDisplayBuilder.toJSON (/home/moonlightcapital/lab-translator/node_modules/@discordjs/builders/dist/index.js:1708:33)
at /home/moonlightcapital/lab-translator/node_modules/@discordjs/builders/dist/index.js:1870:64
at Array.map (<anonymous>)
at ContainerBuilder.toJSON (/home/moonlightcapital/lab-translator/node_modules/@discordjs/builders/dist/index.js:1870:35)
at /home/moonlightcapital/lab-translator/node_modules/discord.js/src/structures/MessagePayload.js:151:46
at Array.map (<anonymous>)
at MessagePayload.resolveBody (/home/moonlightcapital/lab-translator/node_modules/discord.js/src/structures/MessagePayload.js:150:49)
at GuildMessageManager.edit (/home/moonlightcapital/lab-translator/node_modules/discord.js/src/managers/MessageManager.js:186:8)
What exactly am I doing wrong? If I use m.edit({components: [comps[1]]}) to test it replaces the entire message with that container containing "Hello", I just want to be able to refresh a piece of text at a particular location
2 Replies
d.js toolkit
d.js toolkit6mo 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! - Marked as resolved by OP
MoonlightCapital
MoonlightCapitalOP6mo ago
Node version: v24.2.0 Discord.JS version: 14.19.3 oh! i didn't think about it, now that i tried it worked. Thank you!

Did you find this page helpful?