Skip to content

Commit 10e6b4a

Browse files
committed
🌟 feat: Add force re-caching option to cache-messages command
1 parent e4bc7cd commit 10e6b4a

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

‎src/commands/moderation/cache-messages.ts‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PermissionFlagsBits, PermissionsBitField } from 'discord.js';
1+
import { ApplicationCommandOptionType, PermissionFlagsBits, PermissionsBitField } from 'discord.js';
22
import { fetchAndCachePublicChannelsMessages } from '../../util/cache.js';
33
import { createCommand } from '../../util/commands.js';
44

@@ -9,10 +9,18 @@ export default createCommand({
99
default_member_permissions: new PermissionsBitField(
1010
PermissionFlagsBits.ManageMessages
1111
).toJSON(),
12+
options: [
13+
{
14+
name: 'force',
15+
description: 'Force re-caching even if messages are already cached',
16+
type: ApplicationCommandOptionType.Boolean,
17+
required: false,
18+
},
19+
],
1220
},
1321
execute: async (interaction) => {
1422
await interaction.deferReply();
15-
if (!interaction.guild) {
23+
if (!interaction.guild || !interaction.isChatInputCommand()) {
1624
await interaction.editReply('This command can only be used in a guild.');
1725
return;
1826
}
@@ -23,10 +31,14 @@ export default createCommand({
2331
}
2432

2533
const guild = interaction.guild;
34+
const force = interaction.options.getBoolean('force') ?? false;
2635

2736
await interaction.editReply('Caching messages in all public text channels...');
2837

29-
const { cachedChannels, totalChannels } = await fetchAndCachePublicChannelsMessages(guild);
38+
const { cachedChannels, totalChannels } = await fetchAndCachePublicChannelsMessages(
39+
guild,
40+
force
41+
);
3042

3143
await interaction.editReply(
3244
`Cached messages in ${cachedChannels} out of ${totalChannels} text channels.`

0 commit comments

Comments
 (0)