Repository navigation
Expand file tree
/
Copy pathSessions.js
More file actions
68 lines (59 loc) · 2.19 KB
/
Copy pathSessions.js
File metadata and controls
68 lines (59 loc) · 2.19 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
const CONFIG = {
SUGGESTION_CHANNEL_ID: 'YOUR_SUGGESTION_CHANNEL_ID', // channel id here
ACCENT_COLOR: 0x5865f2,
ADD_REACTIONS: true,
};
const {
SlashCommandBuilder,
ContainerBuilder,
TextDisplayBuilder,
SeparatorBuilder,
SeparatorSpacingSize,
MessageFlags,
} = require('discord.js');
function container(title, body, color = CONFIG.ACCENT_COLOR) {
return new ContainerBuilder()
.setAccentColor(color)
.addTextDisplayComponents(new TextDisplayBuilder().setContent(`## ${title}`))
.addSeparatorComponents(
new SeparatorBuilder().setDivider(true).setSpacing(SeparatorSpacingSize.Small),
)
.addTextDisplayComponents(new TextDisplayBuilder().setContent(body));
}
function v2(comp, ephemeral = false) {
return {
components: [comp],
flags: ephemeral
? MessageFlags.IsComponentsV2 | MessageFlags.Ephemeral
: MessageFlags.IsComponentsV2,
};
}
module.exports = {
data: new SlashCommandBuilder()
.setName('suggest')
.setDescription('Submit a suggestion')
.addStringOption((opt) =>
opt.setName('suggestion').setDescription('Your suggestion').setRequired(true).setMaxLength(1500),
),
async execute(interaction) {
if (!CONFIG.SUGGESTION_CHANNEL_ID || CONFIG.SUGGESTION_CHANNEL_ID === 'YOUR_SUGGESTION_CHANNEL_ID') {
await interaction.reply(
v2(container('Suggest Failed', 'Set `SUGGESTION_CHANNEL_ID` at the top of `suggest.js`.'), true),
);
return;
}
const suggestion = interaction.options.getString('suggestion', true);
const channel = await interaction.guild.channels.fetch(CONFIG.SUGGESTION_CHANNEL_ID).catch(() => null);
if (!channel?.isTextBased()) {
await interaction.reply(v2(container('Suggest Failed', 'The suggestion channel ID is invalid.'), true));
return;
}
const body = `${suggestion}\n\n-# Suggested by ${interaction.user} (\`${interaction.user.id}\`)`;
const message = await channel.send(v2(container('Suggestion', body)));
if (CONFIG.ADD_REACTIONS) {
await message.react('👍').catch(() => {});
await message.react('👎').catch(() => {});
}
await interaction.reply(v2(container('Suggestion Sent', `Posted in ${channel}.`), true));
},
};