awaitMessageComponent doesn't wait the set time

Hey there, I'm following the guide but I can't figure out why awaitMessageComponent doesn't wait for the set time. Here's my code:
const { SlashCommandBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, ChannelType, PermissionFlagsBits } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('test')
.setDescription('Testing commands.')
.addChannelOption(option =>
option.setName('from')
.setDescription('Move members from this channel')
.addChannelTypes(ChannelType.GuildVoice, ChannelType.GuildStageVoice)
.setRequired(true))
.addChannelOption(option =>
option.setName('to')
.setDescription('Move members to this channel')
.addChannelTypes(ChannelType.GuildVoice, ChannelType.GuildStageVoice)
.setRequired(true))
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator),

async execute(interaction) {

const from = interaction.options.getChannel('from');
const to = interaction.options.getChannel('to');

// Build confirmation buttons interaction
const confirm = new ButtonBuilder()
.setCustomId('confirm')
.setLabel('Confirm')
.setStyle(ButtonStyle.Success);

const cancel = new ButtonBuilder()
.setCustomId('cancel')
.setLabel('Cancel')
.setStyle(ButtonStyle.Secondary);

const row = new ActionRowBuilder()
.addComponents(cancel, confirm);

await interaction.reply({
content: `Do you want to move people from ${from} to ${to}`,
components: [row],
});

// The filter applied here ensures that only the user who triggered the original interaction can use the buttons.
const collectorFilter = i => i.user.id === interaction.user.id;

try {
const confirmation = await response.awaitMessageComponent({ filter: collectorFilter, time: 60_000 });
console.log("Success");
} catch (e) {
await interaction.editReply({ content: 'Confirmation not received within 1 minute, cancelling', components: [] });
}

},
};
const { SlashCommandBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, ChannelType, PermissionFlagsBits } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('test')
.setDescription('Testing commands.')
.addChannelOption(option =>
option.setName('from')
.setDescription('Move members from this channel')
.addChannelTypes(ChannelType.GuildVoice, ChannelType.GuildStageVoice)
.setRequired(true))
.addChannelOption(option =>
option.setName('to')
.setDescription('Move members to this channel')
.addChannelTypes(ChannelType.GuildVoice, ChannelType.GuildStageVoice)
.setRequired(true))
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator),

async execute(interaction) {

const from = interaction.options.getChannel('from');
const to = interaction.options.getChannel('to');

// Build confirmation buttons interaction
const confirm = new ButtonBuilder()
.setCustomId('confirm')
.setLabel('Confirm')
.setStyle(ButtonStyle.Success);

const cancel = new ButtonBuilder()
.setCustomId('cancel')
.setLabel('Cancel')
.setStyle(ButtonStyle.Secondary);

const row = new ActionRowBuilder()
.addComponents(cancel, confirm);

await interaction.reply({
content: `Do you want to move people from ${from} to ${to}`,
components: [row],
});

// The filter applied here ensures that only the user who triggered the original interaction can use the buttons.
const collectorFilter = i => i.user.id === interaction.user.id;

try {
const confirmation = await response.awaitMessageComponent({ filter: collectorFilter, time: 60_000 });
console.log("Success");
} catch (e) {
await interaction.editReply({ content: 'Confirmation not received within 1 minute, cancelling', components: [] });
}

},
};
Here the intents in index.js
const client = new Client({ intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
] });
const client = new Client({ intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
] });
Any help would be much appreciated
9 Replies
d.js toolkit
d.js toolkit4mo 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! - Marked as resolved by OP
treble/luna
treble/luna4mo ago
Log the error you catch there
fedpep
fedpepOP4mo ago
This is the error:
ReferenceError: response is not defined
at Object.execute (/Users/fpp/Developer/GitHub/discordjs-bot-guide/commands/utility/test.js:47:34)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.execute (/Users/fpp/Developer/GitHub/discordjs-bot-guide/events/interactionCreate.js:16:4)
ReferenceError: response is not defined
at Object.execute (/Users/fpp/Developer/GitHub/discordjs-bot-guide/commands/utility/test.js:47:34)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.execute (/Users/fpp/Developer/GitHub/discordjs-bot-guide/events/interactionCreate.js:16:4)
treble/luna
treble/luna4mo ago
You indeed do not define response you just reply without doing anything Your response is the result of your .reply
fedpep
fedpepOP4mo ago
I understand your answer, but I'm still struggling to understand how to modify the code to make it function properly.
treble/luna
treble/luna4mo ago
interaction.reply returns an InteractionResponse (or message with fetchReply), on which you call .awaitMesaggeComponent. So resolve it into a variable, response in your case
fedpep
fedpepOP4mo ago
Ah ok! Something like:
const response = await interaction.reply({
content: `Do you want to move people from ${from} to ${to}`,
components: [row],
});
const response = await interaction.reply({
content: `Do you want to move people from ${from} to ${to}`,
components: [row],
});
instead of
await interaction.reply({
content: `Do you want to move people from ${from} to ${to}`,
components: [row],
});
await interaction.reply({
content: `Do you want to move people from ${from} to ${to}`,
components: [row],
});
Thanks 🙂
treble/luna
treble/luna4mo ago
yes indeed, should work
fedpep
fedpepOP4mo ago
yes, I can finally see "Success" in the console. Thank you very much 🙌
Want results from more Discord servers?
Add your server