try:
channels_menu = ChannelSelectMenu(
channel_types=[ChannelType.GUILD_TEXT, ChannelType.GUILD_VOICE, ChannelType.GUILD_NEWS, ChannelType.GUILD_FORUM],
placeholder="Select channels",
custom_id="channel_selection",
min_values=1,
max_values=25
)
await ctx.send("Please select channels from the dropdown menu.", components=[channels_menu], ephemeral=True)
except Exception as error:
logger.exception("Error while sending the channel selection menu:")
await ctx.send(f"Error while sending the channel selection menu: {str(error)}", ephemeral=True)
@component_callback("channel_selection")
async def select_channels_callback(self, ctx: ComponentContext):
try:
selected_channel_ids = ctx.values
selected_channels = [ctx.guild.get_channel(int(id)) for id in selected_channel_ids]
selected_channel_names = ', '.join(channel.name for channel in selected_channels if channel)
# Store the selected channels in a dictionary
self.selected_channels_dict[ctx.guild_id] = selected_channels
# Send a confirmation button after the user has selected channels
confirm_button = Button(
style=ButtonStyle.PRIMARY,
label="Confirm Selection",
custom_id="confirm_channels"
)
await ctx.send(f"You selected the following channels: {selected_channel_names}", components=[confirm_button], ephemeral=True)```