Skip to content

Commit e3f7cec

Browse files
committed
🌟 feat: add onboarding command
1 parent 288f0c1 commit e3f7cec

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed

‎src/commands/index.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,21 @@ import { docsCommands } from './docs/index.js';
22
import { guidesCommand } from './guides/index.js';
33
import cacheMessages from './moderation/cache-messages.js';
44
import { repelCommand } from './moderation/repel.js';
5+
import { onboardingCommand } from './onboarding/index.js';
56
import { pingCommand } from './ping.js';
67
import { tipsCommands } from './tips/index.js';
78
import type { Command } from './types.js';
89

910
export const commands = new Map<string, Command>(
10-
[pingCommand, guidesCommand, docsCommands, tipsCommands, repelCommand, cacheMessages]
11+
[
12+
pingCommand,
13+
guidesCommand,
14+
docsCommands,
15+
tipsCommands,
16+
repelCommand,
17+
cacheMessages,
18+
onboardingCommand,
19+
]
1120
.flat()
1221
.map((cmd) => [cmd.data.name, cmd])
1322
);
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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

Comments
 (0)