Skip to content

Commit e4bc7cd

Browse files
committed
🌟 feat: Add cache-messages command to cache messages in all public text channels
1 parent 9bd9c27 commit e4bc7cd

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { PermissionFlagsBits, PermissionsBitField } from 'discord.js';
2+
import { fetchAndCachePublicChannelsMessages } from '../../util/cache.js';
3+
import { createCommand } from '../../util/commands.js';
4+
5+
export default createCommand({
6+
data: {
7+
name: 'cache-messages',
8+
description: 'Cache messages in all text channels of the server',
9+
default_member_permissions: new PermissionsBitField(
10+
PermissionFlagsBits.ManageMessages
11+
).toJSON(),
12+
},
13+
execute: async (interaction) => {
14+
await interaction.deferReply();
15+
if (!interaction.guild) {
16+
await interaction.editReply('This command can only be used in a guild.');
17+
return;
18+
}
19+
20+
if (!interaction.memberPermissions?.has(PermissionFlagsBits.ManageMessages)) {
21+
await interaction.editReply('You do not have permission to use this command.');
22+
return;
23+
}
24+
25+
const guild = interaction.guild;
26+
27+
await interaction.editReply('Caching messages in all public text channels...');
28+
29+
const { cachedChannels, totalChannels } = await fetchAndCachePublicChannelsMessages(guild);
30+
31+
await interaction.editReply(
32+
`Cached messages in ${cachedChannels} out of ${totalChannels} text channels.`
33+
);
34+
35+
return;
36+
},
37+
});

0 commit comments

Comments
 (0)