|
| 1 | +import { ApplicationCommandType, MessageFlags } from 'discord.js'; |
| 2 | +import { config } from '../../env.js'; |
| 3 | +import { createCommand } from '../../util/commands.js'; |
| 4 | +import { containerComponent } from './component.js'; |
| 5 | + |
| 6 | +export const onboardingCommand = createCommand({ |
| 7 | + data: { |
| 8 | + name: 'onboarding', |
| 9 | + description: 'Manage onboarding settings', |
| 10 | + type: ApplicationCommandType.ChatInput, |
| 11 | + }, |
| 12 | + execute: async (interaction) => { |
| 13 | + const guild = interaction.guild; |
| 14 | + if (!guild) { |
| 15 | + await interaction.reply({ |
| 16 | + content: 'This command can only be used in a server.', |
| 17 | + flags: MessageFlags.Ephemeral, |
| 18 | + }); |
| 19 | + return; |
| 20 | + } |
| 21 | + const onboardingRole = guild.roles.cache.get(config.onboarding.roleId); |
| 22 | + if (!onboardingRole) { |
| 23 | + await interaction.reply({ |
| 24 | + content: 'Onboarding role not found. Please check the configuration.', |
| 25 | + flags: MessageFlags.Ephemeral, |
| 26 | + }); |
| 27 | + return; |
| 28 | + } |
| 29 | + const onboardingChannel = guild.channels.cache.get(config.onboarding.channelId); |
| 30 | + if (!onboardingChannel || !onboardingChannel.isSendable()) { |
| 31 | + await interaction.reply({ |
| 32 | + content: |
| 33 | + 'Onboarding channel not found or is not a text channel. Please check the configuration.', |
| 34 | + flags: MessageFlags.Ephemeral, |
| 35 | + }); |
| 36 | + return; |
| 37 | + } |
| 38 | + |
| 39 | + const onboardingMessage = await interaction.reply({ |
| 40 | + components: [containerComponent], |
| 41 | + flags: MessageFlags.IsComponentsV2, |
| 42 | + }); |
| 43 | + |
| 44 | + const collector = onboardingMessage.createMessageComponentCollector({}); |
| 45 | + |
| 46 | + collector.on('collect', async (componentInteraction) => { |
| 47 | + if (componentInteraction.customId === 'onboarding_add_role') { |
| 48 | + const member = await guild.members.fetch(componentInteraction.user.id); |
| 49 | + const hasRole = member.roles.cache.has(onboardingRole.id); |
| 50 | + if (hasRole) { |
| 51 | + await componentInteraction.reply({ |
| 52 | + content: `You already have the ${onboardingRole.name} role.`, |
| 53 | + flags: MessageFlags.Ephemeral, |
| 54 | + }); |
| 55 | + } else { |
| 56 | + await member.roles.add(onboardingRole); |
| 57 | + await componentInteraction.reply({ |
| 58 | + content: `You have been given the ${onboardingRole.name} role!`, |
| 59 | + flags: MessageFlags.Ephemeral, |
| 60 | + }); |
| 61 | + } |
| 62 | + } |
| 63 | + }); |
| 64 | + }, |
| 65 | +}); |
0 commit comments