I'm trying to create a Raffle button where there's a Modal and the Modal sends information about the raffle, and then a button is at the bottom of the Modal code which sends a message via webhook to sign up for the raffle. However, I don't know how to link the raffleId dynamically to the button...
This is what I had for the Raffle button:
const raffleButton = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId(`join-raffle_${raffleID}`)
.setLabel(" Join Raffle")
.setStyle("1")
);
const webhookClient = new WebhookClient({url: webhookUrl });
try {
await webhookClient.send({ embeds: [embed], components: [raffleButton] });
console.log('Raffle message sent successfully!');
} catch (error) {
console.error('Error sending raffle message:', error);
}
And in another file, I have the code for the Raffle:
module.exports = {
data: {
name: `^join-raffle_`
},
async execute(interaction, client) {
const guildId = interaction.guild.id;
const userId = interaction.user.id;
const keyword = interaction.name.split('_')[1];
try {
const joinRaffle = await raffleDB.findOne({
guildid: guildId,
_id: keyword,
expired: false,
});
...
}
I was trying to use wildcards for the name to get it to accept the raffle button custom id, but this doesn't work. Is there any other option I can try? I've tried adjusting things in the handler as well, but not sure what else I can do.
The reason I need customId is because each raffle will have its own id, and it's better to do this dynamically. I also want the button to remain active for the entire life of the raffle, so if I use a temporary button, it will go away.
I thank you for any assistance that can be provided <3