Skip to content

Commit daeb70a

Browse files
author
Harshit Kr Vishwakarma
committed
update tsconfig, add clear command and update help command
1 parent f7b6ba9 commit daeb70a

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

src/commands/core/help.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ const embed = new EmbedBuilder()
3434
{
3535
name: "/ping",
3636
value: "Pings the bot",
37+
},
38+
{
39+
name: "/clear",
40+
value: "clears `n` number of messages",
3741
}
3842
)
3943
.setFooter({

src/commands/mod/clear.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { SlashCommandBuilder } from "discord.js";
2+
3+
const data = new SlashCommandBuilder()
4+
.setName("clear")
5+
.setDescription("clears n number of messages")
6+
.addIntegerOption((option) =>
7+
option
8+
.setName("number")
9+
.setDescription("number of messages you want to delete")
10+
.setRequired(true)
11+
);
12+
13+
const execute = async (interaction: any) => {
14+
try {
15+
const number = interaction.options.getInteger("number");
16+
17+
if (number < 1 || number > 100) {
18+
return await interaction.reply({
19+
content: "Please provide a number between 1 and 100.",
20+
ephemeral: true,
21+
});
22+
}
23+
24+
if (!interaction.member.permissions.has("MANAGE_MESSAGES")) {
25+
return await interaction.reply({
26+
content: "You don't have permission to use this command.",
27+
ephemeral: true,
28+
});
29+
}
30+
31+
const messages = await interaction.channel.messages.fetch({
32+
limit: number + 1,
33+
});
34+
35+
await interaction.channel.bulkDelete(messages);
36+
37+
await interaction.reply({
38+
content: `Successfully deleted ${number} messages.`,
39+
ephemeral: true,
40+
});
41+
} catch (e) {
42+
console.error(e);
43+
}
44+
};
45+
46+
export = {
47+
data,
48+
execute,
49+
};

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,5 +101,6 @@
101101
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
102102
"skipLibCheck": true /* Skip type checking all .d.ts files. */
103103
},
104-
"include": ["src", "play/server.ts", "play/user.ts"]
104+
"include": ["src", "play/server.ts", "play/user.ts"],
105+
"exclude": ["play"]
105106
}

0 commit comments

Comments
 (0)