#respond to button
1 messages · Page 1 of 1 (latest)
Hi
You can make a Component collector in text channel if you are sure user will click the button within minutes or hours
Or it you want to make it permanent, then use "interactionCreate" event
I set up a collector, let me show. I am wondering if this should work.
const { SlashCommandBuilder } = require('@discordjs/builders');
const { MessageActionRow, MessageButton, MessageEmbed } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('ping')
.setDescription('Get the AI latency'),
async execute(client, interaction) {
const row = new MessageActionRow()
.addComponents(
new MessageButton()
.setCustomId('refresh-ping')
.setLabel('Refresh')
.setStyle('PRIMARY'),
);
const embed = new MessageEmbed()
.setColor('AQUA')
.setTitle('Pong!')
.setDescription(`AI Latency: ${client.ws.ping}ms`)
.setTimestamp();
interaction.reply({ embeds: [embed], components: [row] });
const filter = i => i.customId === 'refresh-ping';
const collector = interaction.channel.createMessageComponentCollector({ filter, time: 15000 });
collector.on('collect', async i => {
if (i.customId === 'primary') {
await i.update({ embeds: [embed], components: [] });
}
});
}
}
Going to up the time right now though as 15 seconds is low, changing it to 60 seconds.
@turbid dawn is this how it's supposed to be written? ^^^
Oh yes forgot to change it to refresh-ping
And you have already declared check custom I'd in filter
Copied it off the documentation/guide lol
So now I should have this correct?
collector.on('collect', async i => {
if (i.customId === 'refresh-ping') {
await i.update({ embeds: [embed], components: [row] });
}
});
Yup
You dont even need to specify a time, it is optional so you can just have everything in the same file
Umh but restarting the bot will remove the collector
🙂
Having them in interaction event will make it work after restart too
True