#I'm having trouble editing a post

25 messages · Page 1 of 1 (latest)

jagged shadow
#

I'm trying to change the components (select menu) inside the message, but when I do, I get an unfamiliar error
My code:```js
const message = await interaction.channel.messages.fetch('1036269756405264516');
const data = message.components[0].components[0];

if (data.disabled === false) {
for(let key in data){
data[key].disabled = true;
data[key].placeholder = 'Сейчас недоступно..';
};

const refrashComponents = {
type: 1,
components: [data]
};

await message.edit({ components: [refrashComponents] });
await interaction.reply({
content: 'Проходная временно закрыта. Чтобы вернуть доступ используйте: </passage locking:1036230558189097050>',
ephemeral: true
});
} else {
for(let key in data){
data[key].disabled = true;
data[key].placeholder = 'Сейчас недоступно..';
};

const refrashComponents = {
type: 1,
components: [data]
};

await message.edit({ components: [refrashComponents] });
await interaction.reply({ content: 'Проходная вновь открыта!', ephemeral: true });
};

#

• 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.

#

Error:```js
node:events:504
throw er; // Unhandled 'error' event
^

ValidationError: Expected a string primitive
at StringValidator.handle (A:\Desktop\Work\discord\bots\federal\node_modules@sapphire\shapeshift\dist\index.js:1672:70)
at StringValidator.parse (A:\Desktop\Work\discord\bots\federal\node_modules@sapphire\shapeshift\dist\index.js:113:88)
at validateRequiredSelectMenuParameters (A:\Desktop\Work\discord\bots\federal\node_modules@discordjs\builders\dist\index.js:463:21)
at SelectMenuBuilder.toJSON (A:\Desktop\Work\discord\bots\federal\node_modules@discordjs\builders\dist\index.js:605:5)
at A:\Desktop\Work\discord\bots\federal\node_modules@discordjs\builders\dist\index.js:737:64
at Array.map (<anonymous>)
at ActionRowBuilder.toJSON (A:\Desktop\Work\discord\bots\federal\node_modules@discordjs\builders\dist\index.js:737:35)
at A:\Desktop\Work\discord\bots\federal\node_modules\discord.js\src\structures\MessagePayload.js:137:109
at Array.map (<anonymous>)
at MessagePayload.resolveBody (A:\Desktop\Work\discord\bots\federal\node_modules\discord.js\src\structures\MessagePayload.js:137:49)
Emitted 'error' event on Client instance at:
at emitUnhandledRejectionOrErr (node:events:383:10)
at processTicksAndRejections (node:internal/process/task_queues:85:21) {
validator: 's.string',
given: undefined
}

shell oriole
#

you aren't editing the options of the selectmenu. you are editing all properties of the selectmenu (the type, etc.) and set their disabled and placeholder properties to your values...

#

use SelectMenuBuilder.from(...) and edit the options through that

jagged shadow
shell oriole
#

in your case data would be a SelectMenuComponent

jagged shadow
#

i need add to message.components[0].components[0] data?

#

Like message.components[0].components[0].data

shell oriole
#

that has a disabled property indeed. but then you loop over all properties of data, so key would be customId, data, disabled, maxValues, minValues, options, placeholder, type and you set data[key].disabled and placeholder for all these values of key

shell oriole
jagged shadow
jagged shadow
#

@shell oriole hello again, i have a new bug. I try refresh my select menu back (make disabled = false) but its not work

My code```js
for(let key in data){
data[key].placeholder = 'Выберите действие..';
data[key].disabled = false;
};

const refreshComponents = {
type: 1,
components: [data]
};

console.log(refreshComponents)

await message.edit({ components: [refreshComponents] });
await interaction.reply({ content: 'Проходная вновь открыта!', ephemeral: true });


**console.log:**```js
{
  type: 1,
  components: [
    {
      type: 3,
      custom_id: 'passageSelectMenu',
      min_values: 1,
      max_values: 1,
      placeholder: 'Сейчас недоступно..',
      disabled: true,
      options: [Array]
    }
  ]
}
shell oriole
jagged shadow
jagged shadow
# shell oriole 👆

Unfortunately, there is no option to use constructors, you need to do it manually

violet snowBOT
jagged shadow
#

There is another option for solving this problem. I forgot to mention that if you want to assign a disabled value (the code I'll give in the example below) everything works
This code work ```js
for(let key in data){
data[key].placeholder = 'Сейчас недоступно..';
data[key].disabled = true;
};

const refreshComponents = {
type: 1,
components: [data]
};

await message.edit({ components: [refreshComponents] });
await interaction.reply({ content: 'Проходная временно закрыта. Чтобы вернуть доступ используйте: </passage locking:1036230558189097050>', ephemeral: true });

violet snowBOT
shell oriole
#

They are all there and you can pass the builder to an ActionRow then