(interaction, destination)
| 305 | } |
| 306 | |
| 307 | async function showChannelModal(interaction, destination) { |
| 308 | const label = DESTINATION_LABELS[destination] || destination; |
| 309 | const modalCustomId = `log_dash_channel_modal:${destination}`; |
| 310 | |
| 311 | const channelSelect = new ChannelSelectMenuBuilder() |
| 312 | .setCustomId('log_channel') |
| 313 | .setPlaceholder('Select a text channel…') |
| 314 | .setMinValues(1) |
| 315 | .setMaxValues(1) |
| 316 | .addChannelTypes(ChannelType.GuildText, ChannelType.GuildAnnouncement) |
| 317 | .setRequired(true); |
| 318 | |
| 319 | const channelLabel = new LabelBuilder() |
| 320 | .setLabel(`${label} Channel`) |
| 321 | .setDescription(`Channel where ${label.toLowerCase()} logs will be sent`) |
| 322 | .setChannelSelectMenuComponent(channelSelect); |
| 323 | |
| 324 | const modal = new ModalBuilder() |
| 325 | .setCustomId(modalCustomId) |
| 326 | .setTitle(`Set ${label} Channel`) |
| 327 | .addLabelComponents(channelLabel); |
| 328 | |
| 329 | await interaction.showModal(modal); |
| 330 | |
| 331 | try { |
| 332 | const modalSubmission = await interaction.awaitModalSubmit({ |
| 333 | time: 5 * 60 * 1000, |
| 334 | filter: (i) => i.user.id === interaction.user.id && i.customId === modalCustomId, |
| 335 | }); |
| 336 | |
| 337 | const channelId = modalSubmission.fields.getField('log_channel').values[0]; |
| 338 | const channel = interaction.guild.channels.cache.get(channelId) |
| 339 | ?? await interaction.guild.channels.fetch(channelId).catch(() => null); |
| 340 | |
| 341 | if (!channel) { |
| 342 | return modalSubmission.reply({ |
| 343 | content: '❌ That channel could not be found.', |
| 344 | flags: MessageFlags.Ephemeral, |
| 345 | }); |
| 346 | } |
| 347 | |
| 348 | const botPerms = channel.permissionsFor(interaction.guild.members.me); |
| 349 | if (!botPerms?.has(['ViewChannel', 'SendMessages', 'EmbedLinks'])) { |
| 350 | return modalSubmission.reply({ |
| 351 | content: '❌ I need View Channel, Send Messages, and Embed Links in that channel.', |
| 352 | flags: MessageFlags.Ephemeral, |
| 353 | }); |
| 354 | } |
| 355 | |
| 356 | await setLogChannel(interaction.client, interaction.guildId, destination, channel.id); |
| 357 | |
| 358 | await modalSubmission.reply({ |
| 359 | embeds: [successEmbed('Channel Updated', `**${label}** logs will be sent to ${channel}.`)], |
| 360 | flags: MessageFlags.Ephemeral, |
| 361 | }); |
| 362 | |
| 363 | await refreshDashboardMessage(interaction, interaction.client); |
| 364 | } catch (error) { |
no test coverage detected