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

Commit da10522

Browse files
committed
made shit work
1 parent 01636fc commit da10522

File tree

3 files changed

+43
-74
lines changed

3 files changed

+43
-74
lines changed

src/commands/main/event.ts

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/events/interactionCreate.ts

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,41 @@ export default class ReadyEvent implements GatewayEvent {
55
name: string = 'interactionCreate';
66
once: boolean = false;
77

8-
async code (kogBot: KOGBot, interaction: Interaction) {
8+
async code (kogBot: KOGBot, interaction: Interaction): Promise<void> {
99
if (interaction.isChatInputCommand()) {
10-
const receivedCommand = interaction.commandName;
11-
const params = interaction.options;
12-
13-
const commandObj = kogBot.discord_client.commands.list.find(cmd => cmd.instance.name === receivedCommand);
14-
if (!commandObj) {
15-
interaction.reply("Command not found bro");
10+
let command: any;
11+
12+
console.log(kogBot.discord_client.commands.list);
13+
14+
command = kogBot.discord_client.commands.list.get(interaction.commandName);
15+
16+
if (!command) {
17+
interaction.reply({
18+
embeds:
19+
[
20+
new EmbedBuilder()
21+
.setTitle("Command Execution Error")
22+
.setDescription(`No command was found matching name \`${interaction.commandName}\``)
23+
.setColor(Colors.Red)
24+
.setFooter({
25+
text: `${interaction.guild?.name}`,
26+
iconURL: interaction.guild?.iconURL() as string
27+
})
28+
.setTimestamp()
29+
]
30+
});
1631
return;
1732
}
1833

1934
try {
20-
await commandObj.instance.execute(interaction);
35+
await command.execute(interaction);
2136
} catch (err) {
22-
const replied = interaction.replied || interaction.deferred;
23-
const replyData = {
24-
embeds: [
25-
new EmbedBuilder()
26-
.setTitle("Command Execution Error")
27-
.setDescription(`${err}`)
28-
.setColor(Colors.Red)
29-
.setFooter({
30-
text: `${interaction.guild?.name}`,
31-
iconURL: interaction.guild?.iconURL() as string
32-
})
33-
.setTimestamp()
34-
]
35-
};
37+
console.log(err);
38+
if (interaction.replied || interaction.deferred) {
39+
await interaction.followUp({ content: 'fuck' });
40+
} else {
41+
await interaction.reply({ content: 'shit' });
42+
}
3643
}
3744
}
3845
}

src/index.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Client, IntentsBitField, REST, SlashCommandBuilder, Routes, SlashCommandSubcommandBuilder, RESTPostAPIApplicationCommandsJSONBody } from "discord.js";
1+
import { Client, IntentsBitField, REST, SlashCommandBuilder, Routes, SlashCommandSubcommandBuilder, RESTPostAPIApplicationCommandsJSONBody, Collection } from "discord.js";
22
import fs from 'fs';
33
import knex, { Knex } from "knex";
44
import toml from 'toml';
@@ -76,12 +76,12 @@ class DBot extends Client {
7676
}
7777

7878
commands = {
79-
list: [] as RESTPostAPIApplicationCommandsJSONBody[],
79+
list: new Collection<any, any>(),
8080

8181
parse: async () => {
8282
const folderPath = join(__dirname, 'commands');
8383
const commandCategories = fs.readdirSync(folderPath);
84-
const commands = [];
84+
const commands = new Collection<string, SlashCommand>();
8585

8686
for (const category of commandCategories) {
8787
const commandsPath = join(folderPath, category);
@@ -92,22 +92,29 @@ class DBot extends Client {
9292
const commandClass = (await import(`file://${filePath}`)).default;
9393
const command: SlashCommand = new commandClass(this.kogBot);
9494

95-
commands.push(command.data.toJSON());
95+
commands.set(command.data.name, command);
9696
}
9797
}
9898
return commands;
9999
},
100100

101101
deploy: async () => {
102-
this.commands.list = await this.commands.parse();
102+
const parsed = await this.commands.parse();
103+
this.commands.list = parsed;
104+
const JSONCommands: RESTPostAPIApplicationCommandsJSONBody[] = [];
105+
106+
this.commands.list.forEach((command) => {
107+
JSONCommands.push(command.data.toJSON());
108+
});
109+
103110
if (process.argv.includes('--ci')) {
104111
console.log("Not deploying commands because of CI environment. Commands successfully parsed!")
105112
process.exit(0)
106113
}
107-
console.log(`Deploying ${this.commands.list.length} commands...`);
114+
console.log(`Deploying ${this.commands.list.size} commands...`);
108115
await this.REST.put(
109116
Routes.applicationCommands(this.kogBot.environment.discord.client_id),
110-
{ body: [] }
117+
{ body: JSONCommands }
111118
);
112119
}
113120
}

0 commit comments

Comments
 (0)