Button Interaction

Hello, this is my code:
const {
MessageActionRow,
MessageButton,
ActionRowBuilder,
EmbedBuilder,
ButtonStyle,
ButtonBuilder,
MessageSelectMenu,
User,
MessageComponentInteraction,
InteractionCollector,
GuildMember,
Channel,
SlashCommandBuilder
} = require('discord.js');

const mysql = require('mysql');

module.exports = {
data: new SlashCommandBuilder()
.setName('rules')
.setDescription('Sendet das Regelwerk.')
.setDefaultPermission(false)
.setDMPermission(false),
async execute(interaction) {
const verify = new ButtonBuilder()
.setCustomId('verify')
.setLabel('Verifizieren')
.setStyle(ButtonStyle.Primary)
.setEmoji('1126993747809419295');
const row = new ActionRowBuilder()
.addComponents(verify);
const embed = new EmbedBuilder()
.setColor(0x0099FF)
.setTitle('Web Users')
.setURL('https://discord.js.org/')
.setAuthor({ name: 'Some name', iconURL: 'https://i.imgur.com/AfFp7pu.png', url: 'https://discord.js.org' })
.setDescription('TEST')
.setThumbnail('https://i.imgur.com/AfFp7pu.png')
.addFields(
{ name: 'Regular field title', value: 'Some value here' },
{ name: '\u200B', value: '\u200B' },
{ name: 'Inline field title', value: 'Some value here', inline: true },
{ name: 'Inline field title', value: 'Some value here', inline: true },
)
.addFields({ name: 'Inline field title', value: 'Some value here', inline: true })
.setImage('https://i.imgur.com/AfFp7pu.png')
.setTimestamp()
.setFooter({ text: 'Some footer text here', iconURL: 'https://i.imgur.com/AfFp7pu.png' });
interaction.channel.send({ embeds: [embed], ephemeral: false, components: [row] });
const collector = interaction.channel.createMessageComponentCollector({
componentType: 'BUTTON',
});
collector.on('collect', async (buttonInteraction) => {
if (buttonInteraction.customId === 'verify') {
const user = buttonInteraction.user;
const member = await buttonInteraction.guild.members.fetch(user);
const roleId = '1126996899497517158';
const role = buttonInteraction.guild.roles.cache.get(roleId);

if (role) {
await member.roles.add(role);
await buttonInteraction.reply('Role assigned successfully!', { ephemeral: true});
} else {
await buttonInteraction.reply('Role not found.', { ephemeral: true});
}
}
});
}
};
const {
MessageActionRow,
MessageButton,
ActionRowBuilder,
EmbedBuilder,
ButtonStyle,
ButtonBuilder,
MessageSelectMenu,
User,
MessageComponentInteraction,
InteractionCollector,
GuildMember,
Channel,
SlashCommandBuilder
} = require('discord.js');

const mysql = require('mysql');

module.exports = {
data: new SlashCommandBuilder()
.setName('rules')
.setDescription('Sendet das Regelwerk.')
.setDefaultPermission(false)
.setDMPermission(false),
async execute(interaction) {
const verify = new ButtonBuilder()
.setCustomId('verify')
.setLabel('Verifizieren')
.setStyle(ButtonStyle.Primary)
.setEmoji('1126993747809419295');
const row = new ActionRowBuilder()
.addComponents(verify);
const embed = new EmbedBuilder()
.setColor(0x0099FF)
.setTitle('Web Users')
.setURL('https://discord.js.org/')
.setAuthor({ name: 'Some name', iconURL: 'https://i.imgur.com/AfFp7pu.png', url: 'https://discord.js.org' })
.setDescription('TEST')
.setThumbnail('https://i.imgur.com/AfFp7pu.png')
.addFields(
{ name: 'Regular field title', value: 'Some value here' },
{ name: '\u200B', value: '\u200B' },
{ name: 'Inline field title', value: 'Some value here', inline: true },
{ name: 'Inline field title', value: 'Some value here', inline: true },
)
.addFields({ name: 'Inline field title', value: 'Some value here', inline: true })
.setImage('https://i.imgur.com/AfFp7pu.png')
.setTimestamp()
.setFooter({ text: 'Some footer text here', iconURL: 'https://i.imgur.com/AfFp7pu.png' });
interaction.channel.send({ embeds: [embed], ephemeral: false, components: [row] });
const collector = interaction.channel.createMessageComponentCollector({
componentType: 'BUTTON',
});
collector.on('collect', async (buttonInteraction) => {
if (buttonInteraction.customId === 'verify') {
const user = buttonInteraction.user;
const member = await buttonInteraction.guild.members.fetch(user);
const roleId = '1126996899497517158';
const role = buttonInteraction.guild.roles.cache.get(roleId);

if (role) {
await member.roles.add(role);
await buttonInteraction.reply('Role assigned successfully!', { ephemeral: true});
} else {
await buttonInteraction.reply('Role not found.', { ephemeral: true});
}
}
});
}
};
The Button doesn't reply and nothing happens. Would be thankful.
7 Replies
d.js toolkit
d.js toolkitā€¢2y ago
ā€¢ 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.
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
š•¬š–›š–†š–”š–‹š–‹š–Žš–Ÿš–Žš–Šš–‘š–‘
Thank you ā¤ļø await buttonInteraction.reply('Role assigned successfully!', { ephemeral: true}); Ephemeral doesn't work, do you know why?
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server