19 Replies
- 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!im trying to edit the messsage
Update djs
am
^14.13.0"
now this is
version
Then why did you put 14.0.3 before?
becuse that my old project that im moving from v13
and that wont work on v14
run npm ls discord.js and show the output
beacuse im updated to discord.js@latest
also, try wrapping your components in a new ActionRowBuilder
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
});
}
nothing changes 😢
console output
yeah no
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)
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...
you dont need the newRow
Ir well you do, just not that way
Your newrow is your ActionRowBuilder.from
bump
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
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)
]
});
}