refactor: reorganize project structure and improve user command handling
This commit is contained in:
parent
5cfcb3ba0c
commit
49d6b51de6
7 changed files with 64 additions and 26 deletions
38
index.ts
38
index.ts
|
@ -1,22 +1,23 @@
|
|||
import { ActivityType, Client, Events, GatewayIntentBits, REST, Routes } from "discord.js";
|
||||
import user from "./cmd/user";
|
||||
import { db } from "./db";
|
||||
import { StereoFile } from "./types";
|
||||
import commands from "./cmd";
|
||||
import { db } from "./db/db";
|
||||
import { StereoFile } from "./types/files";
|
||||
|
||||
const client = new Client({
|
||||
intents: [
|
||||
GatewayIntentBits.Guilds,
|
||||
GatewayIntentBits.GuildMessages,
|
||||
GatewayIntentBits.MessageContent,
|
||||
|
||||
]
|
||||
});
|
||||
const rest = new REST({ version: "10" }).setToken(process.env.TOKEN);
|
||||
});
|
||||
|
||||
const rest = new REST({ version: "10" })
|
||||
.setToken(process.env.TOKEN);
|
||||
|
||||
client.once(Events.ClientReady, async (c) => {
|
||||
await rest.put(
|
||||
Routes.applicationCommands(process.env.CLIENT_ID),
|
||||
{ body: commands.map(([data]) => data) }
|
||||
{ body: commands.map(([data, _]) => data) }
|
||||
);
|
||||
|
||||
const files = (await db.all<StereoFile[]>`SELECT * FROM files`).length
|
||||
|
@ -28,20 +29,17 @@ client.once(Events.ClientReady, async (c) => {
|
|||
console.log(c.user.tag);
|
||||
});
|
||||
|
||||
const commands = [
|
||||
user
|
||||
]
|
||||
|
||||
client.on(Events.InteractionCreate, async interaction => {
|
||||
if (!interaction.isChatInputCommand()) return;
|
||||
const cmd = commands.find(([data]) => data.name === interaction.commandName);
|
||||
if (!cmd) return;
|
||||
try {
|
||||
await cmd[1](interaction);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
await interaction.reply({ content: "there was an error executing this command", ephemeral: true });
|
||||
}
|
||||
if (!interaction.isChatInputCommand()) return;
|
||||
const cmd = commands.find(([data]) => data.name === interaction.commandName);
|
||||
if (!cmd) return;
|
||||
|
||||
try {
|
||||
await cmd[1](interaction);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
await interaction.reply({ content: "there was an error executing this command", ephemeral: true });
|
||||
}
|
||||
});
|
||||
|
||||
client.login(process.env.TOKEN).catch((err) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue