-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.ts
More file actions
69 lines (64 loc) · 2.5 KB
/
index.ts
File metadata and controls
69 lines (64 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { ApplicationCommandType, MessageFlags } from 'discord.js';
import { config } from '../../env.js';
import { addRoleToUser } from '../../util/addRoleToUser.js';
import { createCommand } from '../../util/commands.js';
import { containerComponent } from './component.js';
export const onboardingCommand = createCommand({
data: {
name: 'onboarding',
description: 'Manage onboarding settings',
type: ApplicationCommandType.ChatInput,
},
execute: async (interaction) => {
const guild = interaction.guild;
if (!guild) {
await interaction.reply({
content: 'This command can only be used in a server.',
flags: MessageFlags.Ephemeral,
});
return;
}
// @ts-expect-error: This command isn't used and shouldn't affect anything, onboarding roles are TBD
const onboardingRole = guild.roles.cache.get(config.onboarding.roleId);
if (!onboardingRole) {
await interaction.reply({
content: 'Onboarding role not found. Please check the configuration.',
flags: MessageFlags.Ephemeral,
});
return;
}
// @ts-expect-error: This command isn't used and shouldn't affect anything, onboarding channels are TBD
const onboardingChannel = guild.channels.cache.get(config.onboarding.channelId);
if (!onboardingChannel || !onboardingChannel.isSendable()) {
await interaction.reply({
content:
'Onboarding channel not found or is not a text channel. Please check the configuration.',
flags: MessageFlags.Ephemeral,
});
return;
}
const onboardingMessage = await interaction.reply({
components: [containerComponent],
flags: MessageFlags.IsComponentsV2,
});
const collector = onboardingMessage.createMessageComponentCollector({});
collector.on('collect', async (componentInteraction) => {
if (componentInteraction.customId === 'onboarding_add_role') {
try {
const member = await guild.members.fetch(componentInteraction.user.id);
await addRoleToUser(member, onboardingRole);
await componentInteraction.reply({
content: `You have been given the ${onboardingRole.name} role!`,
flags: MessageFlags.Ephemeral,
});
} catch (error) {
await componentInteraction.reply({
content: `Failed to add role. Please contact an administrator.`,
flags: MessageFlags.Ephemeral,
});
console.error('Error adding role:\n', error);
}
}
});
},
});