button label wont update after message.edit

discord.js@latest
No description
No description
19 Replies
d.js toolkit
d.js toolkit15mo 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!
@doniczka
@doniczkaOP15mo ago
im trying to edit the messsage
treble/luna
treble/luna15mo ago
Update djs
@doniczka
@doniczkaOP15mo ago
am ^14.13.0" now this is version
treble/luna
treble/luna15mo ago
Then why did you put 14.0.3 before?
@doniczka
@doniczkaOP15mo ago
becuse that my old project that im moving from v13 and that wont work on v14
treble/luna
treble/luna15mo ago
run npm ls discord.js and show the output
@doniczka
@doniczkaOP15mo ago
No description
@doniczka
@doniczkaOP15mo ago
beacuse im updated to discord.js@latest
treble/luna
treble/luna15mo ago
also, try wrapping your components in a new ActionRowBuilder
@doniczka
@doniczkaOP15mo ago
const m = interaction.message.id;
console.log(m);
const pol = await polls.findOne({ message: m });
if (pol) {
console.log('pol:', pol); // Dodaj ten console.log do debugowania
await interaction.deferReply({
ephemeral: true
});
pol.votes = pol.votes || {};
if (pol.votes[interaction.customId]) pol.votes[interaction.customId] += 1;
else pol.votes[interaction.customId] = 1;
pol.voters.push(interaction.user.id);
await polls.findOneAndUpdate({ message: pol.message }, pol);
await interaction.editReply({ content: "`[ ✔️ ]` Pomyślnie oddano głos w ankiecie!", ephemeral: true });
const m2 = interaction.channel.messages.cache.get(m);


const newRows = m2.components.map(row => {
const newComponents = row.components.map(v => {
v.label = `${pol.votes[v.customId] || 0}`;
console.log(v);
return v;
});
return new ActionRowBuilder().addComponents(newComponents);
});


await interaction.message.edit({
components: newRows
});
}
const m = interaction.message.id;
console.log(m);
const pol = await polls.findOne({ message: m });
if (pol) {
console.log('pol:', pol); // Dodaj ten console.log do debugowania
await interaction.deferReply({
ephemeral: true
});
pol.votes = pol.votes || {};
if (pol.votes[interaction.customId]) pol.votes[interaction.customId] += 1;
else pol.votes[interaction.customId] = 1;
pol.voters.push(interaction.user.id);
await polls.findOneAndUpdate({ message: pol.message }, pol);
await interaction.editReply({ content: "`[ ✔️ ]` Pomyślnie oddano głos w ankiecie!", ephemeral: true });
const m2 = interaction.channel.messages.cache.get(m);


const newRows = m2.components.map(row => {
const newComponents = row.components.map(v => {
v.label = `${pol.votes[v.customId] || 0}`;
console.log(v);
return v;
});
return new ActionRowBuilder().addComponents(newComponents);
});


await interaction.message.edit({
components: newRows
});
}
im do that but
@doniczka
@doniczkaOP15mo ago
No description
@doniczka
@doniczkaOP15mo ago
nothing changes 😢
@doniczka
@doniczkaOP15mo ago
console output
No description
treble/luna
treble/luna15mo ago
yeah no
d.js docs
d.js docs15mo ago
Structures from the API cannot be edited directly. To do so, you can create a new structure (a builder) using the .from() method
const newEmbed = EmbedBuilder.from(embed).setTitle("title")
const newRow = ActionRowBuilder.from(row).addComponents(component)
const newEmbed = EmbedBuilder.from(embed).setTitle("title")
const newRow = ActionRowBuilder.from(row).addComponents(component)
@doniczka
@doniczkaOP15mo ago
const m = interaction.message.id;
console.log(m);
const pol = await polls.findOne({ message: m });
if (pol) {
console.log('pol:', pol);
await interaction.deferReply({
ephemeral: true
});
pol.votes = pol.votes || {};
if (pol.votes[interaction.customId]) pol.votes[interaction.customId] += 1;
else pol.votes[interaction.customId] = 1;
pol.voters.push(interaction.user.id);
await polls.findOneAndUpdate({ message: pol.message }, pol);
await interaction.editReply({ content: "`[ ✔️ ]` Pomyślnie oddano głos w ankiecie!", ephemeral: true });
const m2 = interaction.channel.messages.cache.get(m);


const newRows = m2.components.map(row => {
const newComponents = row.components.map(v => {
v.label = `${pol.votes[v.customId] || 0}`;
console.log(v);
return v;
});
return ActionRowBuilder.from(row).addComponents(newComponents);
});


await interaction.message.edit({
components: newRows
});
}





node:events:491
throw er; // Unhandled 'error' event
^

DiscordAPIError[50035]: Invalid Form Body
components[0].components[2].custom_id[COMPONENT_CUSTOM_ID_DUPLICATED]: Component cus
tom id cannot be duplicated
components[0].components[3].custom_id[COMPONENT_CUSTOM_ID_DUPLICATED]: Component cus
tom id cannot be duplicated
at handleErrors (C:\Users\ziemo\Desktop\botkacpero\node_modules\discord.js\node_
modules\@discordjs\rest\dist\index.js:687:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.runRequest (C:\Users\ziemo\Desktop\botkacpero\node_mo
dules\discord.js\node_modules\@discordjs\rest\dist\index.js:1072:23)
at async SequentialHandler.queueRequest (C:\Users\ziemo\Desktop\botkacpero\node_
modules\discord.js\node_modules\@discordjs\rest\dist\index.js:913:14)
at async _REST.request (C:\Users\ziemo\Desktop\botkacpero\node_modules\discord.j
s\node_modules\@discordjs\rest\dist\index.js:1218:22)
at async GuildMessageManager.edit (C:\Users\ziemo\Desktop\botkacpero\node_module
s\discord.js\src\managers\MessageManager.js:180:15)
at async Object.execute (C:\Users\ziemo\Desktop\botkacpero\src\events\client\int
eractionCreate.js:65:17)
Emitted 'error' event on Client instance at:
at emitUnhandledRejectionOrErr (node:events:394:10)
at process.processTicksAndRejections (node:internal/process/task_queues:84:21) {
requestBody: {
files: [],
json: {
content: undefined,
tts: false,
nonce: undefined,
embeds: undefined,
components: [
{
type: 1,
components: [ [Object], [Object], [Object], [Object] ]
}
],
username: undefined,
avatar_url: undefined,
allowed_mentions: undefined,
flags: 0,
message_reference: undefined,
attachments: undefined,
sticker_ids: undefined,
thread_name: undefined
}
},
rawError: {
message: 'Invalid Form Body',
code: 50035,
errors: {
components: { '0': { components: { '2': [Object], '3': [Object] } } }
}
},
code: 50035,
status: 400,
method: 'PATCH',
url: 'https://discord.com/api/v10/channels/1027264053191655516/messages/1149419511
028658296'
}

Node.js v18.16.0
[nodemon] app crashed - waiting for file changes before starting...
const m = interaction.message.id;
console.log(m);
const pol = await polls.findOne({ message: m });
if (pol) {
console.log('pol:', pol);
await interaction.deferReply({
ephemeral: true
});
pol.votes = pol.votes || {};
if (pol.votes[interaction.customId]) pol.votes[interaction.customId] += 1;
else pol.votes[interaction.customId] = 1;
pol.voters.push(interaction.user.id);
await polls.findOneAndUpdate({ message: pol.message }, pol);
await interaction.editReply({ content: "`[ ✔️ ]` Pomyślnie oddano głos w ankiecie!", ephemeral: true });
const m2 = interaction.channel.messages.cache.get(m);


const newRows = m2.components.map(row => {
const newComponents = row.components.map(v => {
v.label = `${pol.votes[v.customId] || 0}`;
console.log(v);
return v;
});
return ActionRowBuilder.from(row).addComponents(newComponents);
});


await interaction.message.edit({
components: newRows
});
}





node:events:491
throw er; // Unhandled 'error' event
^

DiscordAPIError[50035]: Invalid Form Body
components[0].components[2].custom_id[COMPONENT_CUSTOM_ID_DUPLICATED]: Component cus
tom id cannot be duplicated
components[0].components[3].custom_id[COMPONENT_CUSTOM_ID_DUPLICATED]: Component cus
tom id cannot be duplicated
at handleErrors (C:\Users\ziemo\Desktop\botkacpero\node_modules\discord.js\node_
modules\@discordjs\rest\dist\index.js:687:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.runRequest (C:\Users\ziemo\Desktop\botkacpero\node_mo
dules\discord.js\node_modules\@discordjs\rest\dist\index.js:1072:23)
at async SequentialHandler.queueRequest (C:\Users\ziemo\Desktop\botkacpero\node_
modules\discord.js\node_modules\@discordjs\rest\dist\index.js:913:14)
at async _REST.request (C:\Users\ziemo\Desktop\botkacpero\node_modules\discord.j
s\node_modules\@discordjs\rest\dist\index.js:1218:22)
at async GuildMessageManager.edit (C:\Users\ziemo\Desktop\botkacpero\node_module
s\discord.js\src\managers\MessageManager.js:180:15)
at async Object.execute (C:\Users\ziemo\Desktop\botkacpero\src\events\client\int
eractionCreate.js:65:17)
Emitted 'error' event on Client instance at:
at emitUnhandledRejectionOrErr (node:events:394:10)
at process.processTicksAndRejections (node:internal/process/task_queues:84:21) {
requestBody: {
files: [],
json: {
content: undefined,
tts: false,
nonce: undefined,
embeds: undefined,
components: [
{
type: 1,
components: [ [Object], [Object], [Object], [Object] ]
}
],
username: undefined,
avatar_url: undefined,
allowed_mentions: undefined,
flags: 0,
message_reference: undefined,
attachments: undefined,
sticker_ids: undefined,
thread_name: undefined
}
},
rawError: {
message: 'Invalid Form Body',
code: 50035,
errors: {
components: { '0': { components: { '2': [Object], '3': [Object] } } }
}
},
code: 50035,
status: 400,
method: 'PATCH',
url: 'https://discord.com/api/v10/channels/1027264053191655516/messages/1149419511
028658296'
}

Node.js v18.16.0
[nodemon] app crashed - waiting for file changes before starting...
ok. now its error beacuse its duplicated buttons
treble/luna
treble/luna15mo ago
you dont need the newRow Ir well you do, just not that way Your newrow is your ActionRowBuilder.from
@doniczka
@doniczkaOP15mo ago
bump
const m = interaction.message.id;
console.log(m);
const pol = await polls.findOne({ message: m });
if (pol) {
console.log('pol:', pol);
await interaction.deferReply({
ephemeral: true
});
pol.votes = pol.votes || {};
if (pol.votes[interaction.customId]) pol.votes[interaction.customId] += 1;
else pol.votes[interaction.customId] = 1;
pol.voters.push(interaction.user.id);
await polls.findOneAndUpdate({ message: pol.message }, pol);
await interaction.editReply({ content: "`[ ✔️ ]` Pomyślnie oddano głos w ankiecie!", ephemeral: true });
const m2 = interaction.channel.messages.cache.get(m);


const newComponents = m2.components[0].components.map(v => {
if (v.customId === interaction.customId) {
v.label = `${pol.votes[interaction.customId] || 0}`;
}
return v;
});


await m2.edit({
components: [
new ActionRowBuilder()
.addComponents(newComponents)
]
});
}
const m = interaction.message.id;
console.log(m);
const pol = await polls.findOne({ message: m });
if (pol) {
console.log('pol:', pol);
await interaction.deferReply({
ephemeral: true
});
pol.votes = pol.votes || {};
if (pol.votes[interaction.customId]) pol.votes[interaction.customId] += 1;
else pol.votes[interaction.customId] = 1;
pol.voters.push(interaction.user.id);
await polls.findOneAndUpdate({ message: pol.message }, pol);
await interaction.editReply({ content: "`[ ✔️ ]` Pomyślnie oddano głos w ankiecie!", ephemeral: true });
const m2 = interaction.channel.messages.cache.get(m);


const newComponents = m2.components[0].components.map(v => {
if (v.customId === interaction.customId) {
v.label = `${pol.votes[interaction.customId] || 0}`;
}
return v;
});


await m2.edit({
components: [
new ActionRowBuilder()
.addComponents(newComponents)
]
});
}
i have update to like that and 0 errors displays but the button labels wont update okay solved stupid error like v.data.label is working in forEach but v.label is not working XD
Want results from more Discord servers?
Add your server