Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.

Commit 45541cf

Browse files
committed
feat: Make it so commands only deploy to discord if the --deploy argv is passed in the process thread thing.
1 parent 6dc7b4a commit 45541cf

File tree

5 files changed

+86
-41
lines changed

5 files changed

+86
-41
lines changed

src/commands/misc/kill.ts

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,33 @@
1-
import { EmbedBuilder, ChatInputCommandInteraction, SlashCommandBuilder, SlashCommandUserOption, SlashCommandSubcommandBuilder } from "discord.js";
1+
import { EmbedBuilder, ChatInputCommandInteraction, SlashCommandBuilder, SlashCommandUserOption, SlashCommandSubcommandBuilder, SlashCommandRoleOption } from "discord.js";
22
import { KOGBot } from "../../index.js";
33

44
class KillCommand implements SlashCommand {
55
data = new SlashCommandBuilder()
6-
.setName('kill')
7-
.setDescription('Kill a user.')
6+
.setName('kill')
7+
.setDescription('Kills an entity')
8+
.addSubcommand((subcommand: SlashCommandSubcommandBuilder) =>
9+
subcommand
10+
.setName('user')
11+
.setDescription('The user to kill.')
12+
.addUserOption((option: SlashCommandUserOption) =>
13+
option
14+
.setName('user')
15+
.setDescription('The user to kill.')
16+
.setRequired(true)
17+
)
18+
)
19+
.addSubcommand((subcommand: SlashCommandSubcommandBuilder) =>
20+
subcommand
21+
.setName('role')
22+
.setDescription('The role to kill.')
23+
.addRoleOption((option: SlashCommandRoleOption) =>
24+
option
25+
.setName('role')
26+
.setDescription('The role to kill.')
27+
.setRequired(true)
28+
)
29+
)
30+
831
dev = true;
932
kogBot: KOGBot;
1033

@@ -13,30 +36,8 @@ class KillCommand implements SlashCommand {
1336
}
1437

1538
async execute(interaction: ChatInputCommandInteraction): Promise<void> {
16-
try {
17-
const user = interaction.options.getUser('user');
18-
if (!user) {
19-
interaction.reply("No user was mentioned. Please mention a user to kill.");
20-
return;
21-
}
22-
23-
const embed = new EmbedBuilder()
24-
.setColor("#9033FF")
25-
.setTitle('Killed')
26-
.setDescription(`I have killed the stinky of <@${user.id}>`);
27-
28-
await interaction.reply({ embeds: [embed] });
29-
} catch (error) {
30-
console.error("Error in executing kill command:", error);
31-
32-
const errorEmbed = new EmbedBuilder()
33-
.setColor("#E73A3A")
34-
.setTitle("Error")
35-
.setDescription("An error occurred while executing the kill command.")
36-
.setTimestamp();
37-
38-
await interaction.reply({ embeds: [errorEmbed], ephemeral: true });
39-
}
39+
const subCommand = interaction.options.getSubcommand();
40+
console.log(subCommand);
4041
}
4142
}
4243

src/commands/misc/ping.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ class PingCommand implements SlashCommand {
55
data = new SlashCommandBuilder()
66
.setName('ping')
77
.setDescription('Check the bot\'s latency.');
8-
dev = true;
98
kogBot: KOGBot;
109

1110
constructor(kogBot: KOGBot) {

src/events/interactionCreate.ts

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,39 @@ export default class ReadyEvent implements GatewayEvent {
77

88
async code (kogBot: KOGBot, interaction: Interaction): Promise<void> {
99
if (interaction.isChatInputCommand()) {
10-
let command: any;
11-
12-
console.log(kogBot.discord_client.commands.list);
13-
14-
command = kogBot.discord_client.commands.list.get(interaction.commandName);
10+
if (!interaction.guild) {
11+
if (interaction.replied || interaction.deferred) {
12+
await interaction.followUp({
13+
embeds: [
14+
new EmbedBuilder()
15+
.setTitle("Command Execution Error")
16+
.setDescription("Commands can only be executed inside guilds.")
17+
.setColor(Colors.Red)
18+
.setFooter({
19+
text: `${interaction.user.username}`,
20+
iconURL: interaction.user.avatarURL() as string
21+
})
22+
.setTimestamp()
23+
]
24+
})
25+
} else {
26+
await interaction.reply({
27+
embeds: [
28+
new EmbedBuilder()
29+
.setTitle("Command Execution Error")
30+
.setDescription("Commands can only be executed inside guilds.")
31+
.setColor(Colors.Red)
32+
.setFooter({
33+
text: `${interaction.user.username}`,
34+
iconURL: interaction.user.avatarURL() as string
35+
})
36+
.setTimestamp()
37+
]
38+
})
39+
}
40+
return;
41+
}
42+
let command: SlashCommand = kogBot.discord_client.commands.list.get(interaction.commandName);
1543

1644
if (!command) {
1745
interaction.reply({
@@ -29,6 +57,21 @@ export default class ReadyEvent implements GatewayEvent {
2957
]
3058
});
3159
return;
60+
} else if (command.dev && !kogBot.environment.discord.dev_ids.includes(interaction.user.id)) {
61+
interaction.reply({
62+
embeds: [
63+
new EmbedBuilder()
64+
.setTitle("Command Execution Error")
65+
.setDescription(`Command \`${interaction.commandName}\` is a developer only command and cannot be executed by non-developers.`)
66+
.setColor(Colors.Red)
67+
.setFooter({
68+
text: `${interaction.guild?.name}`,
69+
iconURL: interaction.guild?.iconURL() as string
70+
})
71+
.setTimestamp()
72+
]
73+
});
74+
return;
3275
}
3376

3477
try {

src/index.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Client, IntentsBitField, REST, SlashCommandBuilder, Routes, SlashCommandSubcommandBuilder, RESTPostAPIApplicationCommandsJSONBody, Collection } from "discord.js";
1+
import { Client, IntentsBitField, REST, Routes, RESTPostAPIApplicationCommandsJSONBody, Collection } from "discord.js";
22
import fs from 'fs';
33
import knex, { Knex } from "knex";
44
import toml from 'toml';
@@ -111,11 +111,13 @@ class DBot extends Client {
111111
console.log("Not deploying commands because of CI environment. Commands successfully parsed!")
112112
process.exit(0)
113113
}
114-
console.log(`Deploying ${this.commands.list.size} commands...`);
115-
await this.REST.put(
116-
Routes.applicationCommands(this.kogBot.environment.discord.client_id),
117-
{ body: JSONCommands }
118-
);
114+
if (process.argv.includes('--deploy')) {
115+
console.log(`Publishing ${this.commands.list.size} commands to the Discord API...`);
116+
await this.REST.put(
117+
Routes.applicationCommands(this.kogBot.environment.discord.client_id),
118+
{ body: JSONCommands }
119+
);
120+
}
119121
}
120122
}
121123
}

src/types/main.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ApplicationCommandOptionBase, ChatInputCommandInteraction, SlashCommandBuilder, SlashCommandSubcommandBuilder } from "discord.js";
1+
import { ApplicationCommandOptionBase, ChatInputCommandInteraction, SlashCommandBuilder, SlashCommandSubcommandBuilder, SlashCommandSubcommandsOnlyBuilder } from "discord.js";
22
import { KOGBot } from "index.ts";
33

44
global {
@@ -15,7 +15,7 @@ global {
1515
}
1616

1717
declare interface SlashCommand {
18-
data: SlashCommandBuilder;
18+
data: SlashCommandBuilder | SlashCommandSubcommandsOnlyBuilder;
1919
dev?: boolean;
2020
kogBot: KOGBot;
2121

0 commit comments

Comments
 (0)