Squid
Squid
DIAdiscord.js - Imagine an app
Created by Squid on 11/4/2022 in #djs-questions
Message Component Collector Component Types
If you create a component collector on a message while listening for only one component type, you can simply pass componentType: ComponentType.... into your options object. However, if you have a message with multiple component types and want a collector that listens for any type, then you have to pass a generic union into the method since the options object only allows one componentType, not an array; excluding the componentType makes collected return unknown. Is this the intended best method of doing such? Minimum reproducible example:
const menuRow = new ActionRowBuilder<SelectMenuBuilder>().setComponents(new SelectMenuBuilder());
const buttonRow = new ActionRowBuilder<ButtonBuilder>().setComponents(new ButtonBuilder());

const message = await interaction.reply({ content: 'Hi', components: [menuRow, buttonRow], fetchReply: true });

const collected = await message.awaitMessageComponent<ComponentType.StringSelect | ComponentType.Button>({ // Generic must be specified here similar to the row builders
filter: i => i.user.id === interaction.user.id,
time: 3000
});
const menuRow = new ActionRowBuilder<SelectMenuBuilder>().setComponents(new SelectMenuBuilder());
const buttonRow = new ActionRowBuilder<ButtonBuilder>().setComponents(new ButtonBuilder());

const message = await interaction.reply({ content: 'Hi', components: [menuRow, buttonRow], fetchReply: true });

const collected = await message.awaitMessageComponent<ComponentType.StringSelect | ComponentType.Button>({ // Generic must be specified here similar to the row builders
filter: i => i.user.id === interaction.user.id,
time: 3000
});
DJS v14.6.0, Node v19.0.0
2 replies