Edit message according to selected value

Hello, I've created an embed and a selectMenu just below it and I'd like to modify the embed (and therefore the message) according to the value chosen. I've tried something but it doesn't work Could you please help me? (I don't know if my explanation is very clear, so I've tried to schematize it in the attachment with the code.)
27 Replies
d.js toolkit
d.js toolkitβ€’16mo 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!
Black_Wither
Black_Witherβ€’16mo ago
Do you get a error or something?
π‘†π‘˜π‘’π‘™π‘™π‘¦ ࢞
This is because I put " if (Option === 'commands') { " but I don't know how to retrieve the previous value.
Black_Wither
Black_Witherβ€’16mo ago
ah I see. If you want to make the select menu available for any period of time after command usage you need a listener, otherwise you need a handler for select menus. The method to call the select menu is interaction.values[0] for example:
if(interaction.customId == 'helppageredirect') {
if(interaction.values[0] == 'commandes'){
//[…]
}
}
if(interaction.customId == 'helppageredirect') {
if(interaction.values[0] == 'commandes'){
//[…]
}
}
π‘†π‘˜π‘’π‘™π‘™π‘¦ ࢞
I want to do something like this It will be possible with this method
π‘†π‘˜π‘’π‘™π‘™π‘¦ ࢞
I'm sorry if I'm not clear in my explanations, but I can't describe exactly what I want (+I use a translator to talk to you).
Black_Wither
Black_Witherβ€’16mo ago
yes because with interaction.customId you ask for the Id from the select menu and with interaction.values[0] you ask for the first input from the select menu
π‘†π‘˜π‘’π‘™π‘™π‘¦ ࢞
Okay, thanks, I'll do that and let you know if it works. *My diagram is really unclear 😒 *
Black_Wither
Black_Witherβ€’16mo ago
so you can ask for:
if(interacrion.values[0] == 'commands') {
//interaction.update(…)
}
else if(interaction.values[0] == 'second_option') {
//interaction.update(…)
}
if(interacrion.values[0] == 'commands') {
//interaction.update(…)
}
else if(interaction.values[0] == 'second_option') {
//interaction.update(…)
}
d.js docs
d.js docsβ€’16mo ago
π‘†π‘˜π‘’π‘™π‘™π‘¦ ࢞
Isn't it interaction.editReply to edit a message? And do I need to redo an entire embed to modify the first one, or can I just modify certain values (like the name, fields)?
π‘†π‘˜π‘’π‘™π‘™π‘¦ ࢞
I've done this but it doesn't work (I think it's because I'm defining a new embed).
π‘†π‘˜π‘’π‘™π‘™π‘¦ ࢞
Please let me know when you return.
Black_Wither
Black_Witherβ€’16mo ago
It returns nothing right? you need a listener or handler for the select menu, you use a slash command handler for the slash command, the same you need for select menus
π‘†π‘˜π‘’π‘™π‘™π‘¦ ࢞
Only this (Interaction failure in french)
π‘†π‘˜π‘’π‘™π‘™π‘¦ ࢞
How do I do this in my code? Sorry but I'm looking in the doc but I can't find it.
Black_Wither
Black_Witherβ€’16mo ago
put in your main file: client.on('interactionCreate', async interaction => { [select Menu code] } for the first its enough
π‘†π‘˜π‘’π‘™π‘™π‘¦ ࢞
Here is the main file (and the startup file as well) I can put this piece of code anywhere in it ?
Black_Wither
Black_Witherβ€’16mo ago
const fs = require('node:fs');
const path = require('node:path');
const { Client, Collection, Events, GatewayIntentBits } = require('discord.js');
const { token } = require('./config.json');

const client = new Client({ intents: [GatewayIntentBits.Guilds] });

client.commands = new Collection();
const commandsPath = path.join(__dirname, 'commands');
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));

for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
client.commands.set(command.data.name, command);
}

client.once(Events.ClientReady, () => {
console.log('PrΓͺt !');
});

client.on(Events.InteractionCreate, async interaction => {

if(interaction.customId == 'helppageredirect') {
if(interaction.values[0] == 'commandes'){
const commandes = new EmbedBuilder()
.setTitle('Commandes')
.setDescription('Voici la liste des commandes :')
.setColor(0xcd6f57)
.setAuthor({
url: `https://discord.gg/56aN5xCqnQ`,
iconURL: interaction.user.displayAvatarURL(),
name: interaction.user.tag
})
await interaction.update({
embeds: [commandes],
})
}
}
if (!interaction.isChatInputCommand()) return;

const command = client.commands.get(interaction.commandName);

if (!command) return;

try {
await command.execute(interaction);
} catch (error) {
console.error(error);
await interaction.reply({ content: 'Il y a un problème lors de l\'exécution de la commande ! Veuillez vérifier le code ou demander de l\'aide à un administrateur !', ephemeral: true });
}
});

client.login(token);
const fs = require('node:fs');
const path = require('node:path');
const { Client, Collection, Events, GatewayIntentBits } = require('discord.js');
const { token } = require('./config.json');

const client = new Client({ intents: [GatewayIntentBits.Guilds] });

client.commands = new Collection();
const commandsPath = path.join(__dirname, 'commands');
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));

for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
client.commands.set(command.data.name, command);
}

client.once(Events.ClientReady, () => {
console.log('PrΓͺt !');
});

client.on(Events.InteractionCreate, async interaction => {

if(interaction.customId == 'helppageredirect') {
if(interaction.values[0] == 'commandes'){
const commandes = new EmbedBuilder()
.setTitle('Commandes')
.setDescription('Voici la liste des commandes :')
.setColor(0xcd6f57)
.setAuthor({
url: `https://discord.gg/56aN5xCqnQ`,
iconURL: interaction.user.displayAvatarURL(),
name: interaction.user.tag
})
await interaction.update({
embeds: [commandes],
})
}
}
if (!interaction.isChatInputCommand()) return;

const command = client.commands.get(interaction.commandName);

if (!command) return;

try {
await command.execute(interaction);
} catch (error) {
console.error(error);
await interaction.reply({ content: 'Il y a un problème lors de l\'exécution de la commande ! Veuillez vérifier le code ou demander de l\'aide à un administrateur !', ephemeral: true });
}
});

client.login(token);
π‘†π‘˜π‘’π‘™π‘™π‘¦ ࢞
All right, I'll try it this way Is there any reason why we can't put this piece of code in the help.js file (the bot's command) directly (instead of the main file, because I try to keep it to a minimum)? And since we've put the code in this file, I can delete it from the other one (help.js).
Black_Wither
Black_Witherβ€’16mo ago
you can put it in with an listener, but this is only temporary. A other possibility is, that you create a select menu handler, what this is, you can search in the internet yes
π‘†π‘˜π‘’π‘™π‘™π‘¦ ࢞
What do you mean by "temporary"? And okay, I'll do my research on that, but for now I'll leave this bit of code in the main file. And thank you very much, everything works as expected ❀️
Black_Wither
Black_Witherβ€’16mo ago
no problem like you have for example 30mins to select something or when the bot restart you need to make the command again to click something in the select menu I hope you understand what I say because Iβ€˜m german and dont talk very well english xD
π‘†π‘˜π‘’π‘™π‘™π‘¦ ࢞
Okay, I understand. Yes, I understand what you've explained to me, but the hardest part was for you to understand me xD (I'm French, so I don't speak English well).
Want results from more Discord servers?
Add your server