i need one interaction on select Replace the interaction 1

module.exports = {
data: new SlashCommandBuilder()
.setName("addrole")
.setDescription("Add Role To Member in Server")
.setDefaultMemberPermissions(PermissionFlagsBits.ManageRoles)
.addUserOption(option =>
option.setName("user")
.setDescription("User to add the role")
.setRequired(true)
),
async execute(interaction) {
const { options } = interaction;
const role = options.getRole("role"); // Use getRole to retrieve the role option
const member = interaction.guild.members.cache.get(options.getUser("user").id);
const select = new StringSelectMenuBuilder()


.setCustomId("added")
.setPlaceholder("Member Role add")
.addOptions(
{
label: 'Helper Role',
value: 'helperrole'
},
{
label: 'Admin',
value: 'adminrole'
},
)

const row = new ActionRowBuilder().addComponents(select);

const collector = interaction.channel.createMessageComponentCollector()

const reply =

await interaction.reply({ content: "Test", components: [row] , ephemeral: true });

collector.on('collect', async i => {
if (i.customId.includes("added")) {
const selctedValue= i.values[0];

if (selctedValue == `helperrole`) {
member.roles.add(config.helperid);

const addroleembed = new Discord.EmbedBuilder()
.setDescription(`Added role <@&${config.helperid}> to user named ${member.user.tag}`)
.setTimestamp();

await interaction.followUp({embeds: [addroleembed] , ephemeral: true });


}

if (selctedValue == `adminrole`) {
member.roles.add(config.adminid);

const addroleembed = new Discord.EmbedBuilder()
.setDescription(`Added role <@&${config.adminid}> to user named ${member.user.tag}`)
.setTimestamp();

await interaction.followUp({embeds: [addroleembed] , ephemeral: true });


}


}

})

},
};
module.exports = {
data: new SlashCommandBuilder()
.setName("addrole")
.setDescription("Add Role To Member in Server")
.setDefaultMemberPermissions(PermissionFlagsBits.ManageRoles)
.addUserOption(option =>
option.setName("user")
.setDescription("User to add the role")
.setRequired(true)
),
async execute(interaction) {
const { options } = interaction;
const role = options.getRole("role"); // Use getRole to retrieve the role option
const member = interaction.guild.members.cache.get(options.getUser("user").id);
const select = new StringSelectMenuBuilder()


.setCustomId("added")
.setPlaceholder("Member Role add")
.addOptions(
{
label: 'Helper Role',
value: 'helperrole'
},
{
label: 'Admin',
value: 'adminrole'
},
)

const row = new ActionRowBuilder().addComponents(select);

const collector = interaction.channel.createMessageComponentCollector()

const reply =

await interaction.reply({ content: "Test", components: [row] , ephemeral: true });

collector.on('collect', async i => {
if (i.customId.includes("added")) {
const selctedValue= i.values[0];

if (selctedValue == `helperrole`) {
member.roles.add(config.helperid);

const addroleembed = new Discord.EmbedBuilder()
.setDescription(`Added role <@&${config.helperid}> to user named ${member.user.tag}`)
.setTimestamp();

await interaction.followUp({embeds: [addroleembed] , ephemeral: true });


}

if (selctedValue == `adminrole`) {
member.roles.add(config.adminid);

const addroleembed = new Discord.EmbedBuilder()
.setDescription(`Added role <@&${config.adminid}> to user named ${member.user.tag}`)
.setTimestamp();

await interaction.followUp({embeds: [addroleembed] , ephemeral: true });


}


}

})

},
};
No description
2 Replies
d.js toolkit
d.js toolkit14mo 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!
duck
duck14mo ago
<Interaction>.followUp() just sends a follow up message to an interaction since you're not responding to the component interaction anywhere, I'd suggest using <ComponentInteraction>.update() which properly responds to the interaction (so that you don't get the "This interaction failed" message) and updates the message the component is on
Want results from more Discord servers?
Add your server