import { ChatInputCommandInteraction, WebhookEditMessageOptions, ChannelType, ActionRowBuilder, SelectMenuBuilder, ComponentType, GuildChannel, } from 'discord.js'; import Bot from '../base/Bot'; import IData from './IData'; async function selectChannelMenu( client: Bot, interaction: ChatInputCommandInteraction, data: IData, replyOptions: { selectMenu: WebhookEditMessageOptions; selectMessage: WebhookEditMessageOptions; afterUpdate: WebhookEditMessageOptions; componentCustomId: string; }, ) { if (!interaction.isCommand()) return; if (!interaction.deferred) await interaction.deferReply(); if (!interaction.inCachedGuild()) return; if (!data.guild) data.guild = await client.findOrCreateGuild(interaction.guild.id); if (!data.guild.economy) data.guild.economy = {}; if (!data.guild.economy.startChannel) { if ((await interaction.guild.channels.fetch()).filter(c => c.type == ChannelType.GuildText).size < 1) return interaction.editReply('Es muss mindestens ein Channel existieren.'); if ((await interaction.guild.channels.fetch()).filter(c => c.type == ChannelType.GuildText).size! <= 25) { const options = (await interaction.guild.channels.fetch()) .filter(c => c.type == ChannelType.GuildText) .map(c => { return { label: c.name, // description: `<#${c.id}>`, value: c.id, }; }); replyOptions.selectMenu.components?.push( new ActionRowBuilder().addComponents( new SelectMenuBuilder({ options: options, customId: replyOptions.componentCustomId, }), ), ); const reply = await interaction.editReply(replyOptions.selectMenu); const filter = i => { if (!i.isSelectMenu()) return false; if (i.user.id == interaction.user.id) return true; return false; }; try { const collector = await reply.awaitMessageComponent({ filter, componentType: ComponentType.SelectMenu, time: 60000, }); const channel = (await interaction.guild.channels.fetch()).get(collector.values[0]); if (!channel) return interaction.editReply('Es wurde kein gültiger Channel ausgewählt, Vorgang abgebrochen.'); interaction.editReply(replyOptions.afterUpdate); collector.update(replyOptions.afterUpdate); return channel; } catch (error) { if (error.code == 'INTERACTION_COLLECTOR_ERROR') { return interaction.editReply({ embeds: [], components: [], content: 'Du hast nicht schnell genug geantwortet, der Vorgang wird abgebrochen.', }); } else return interaction.editReply(`Der Prozess wurde durch diesen Fehler abgebrochen: ${error}`); } } else { await interaction.editReply(replyOptions.selectMessage); if (!interaction.channel) return; console.log('s'); try { const channel = await interaction.channel.awaitMessages({ filter: m => { let valid = true; console.log(m.content); console.log(m.mentions.channels.toJSON()); if (m.author.id != interaction.user.id) valid = false; let ch: GuildChannel; if (m.mentions.channels.size <= 1) { ch = m.mentions.channels.first()! as GuildChannel; } else { ch = m.guild?.channels.cache.get(m.content.trim()) as GuildChannel; } if (!ch) return false; if (ch.type != ChannelType.GuildText) valid = false; return valid; }, time: 60000, max: 1, errors: ['time'], }); if (!channel) return interaction.editReply('Es wurde kein gültiger Channel ausgewählt, Vorgang abgebrochen.'); return channel; } catch (error) { // console.log(error.code); if (error.code == 'INTERACTION_COLLECTOR_ERROR') { return interaction.editReply({ embeds: [], components: [], content: 'Du hast nicht schnell genug geantwortet, der Vorgang wird abgebrochen.', }); } else return interaction.editReply(`Der Prozess wurde durch diesen Fehler abgebrochen: ${error}`); } } } } export { selectChannelMenu };