bug resolutions

This commit is contained in:
Lukian LEIZOUR 2024-03-15 21:48:47 +01:00
parent ec835b03e3
commit ac0672f13a
7 changed files with 53 additions and 42 deletions

View file

@ -3,6 +3,7 @@
"version": "1.0.0", "version": "1.0.0",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"type": "module",
"scripts": { "scripts": {
"dev": "tsx watch src", "dev": "tsx watch src",
"build": "tsc", "build": "tsc",

View file

@ -1,6 +1,6 @@
import { SlashCommandBuilder, ChatInputCommandInteraction } from "discord.js"; import { SlashCommandBuilder, ChatInputCommandInteraction } from "discord.js";
module.exports = { export default {
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
.setName("ping") .setName("ping")
.setDescription("Replies with Pong!"), .setDescription("Replies with Pong!"),

View file

@ -1,6 +1,6 @@
import { Events, Interaction } from "discord.js"; import { Events, Interaction } from "discord.js";
module.exports = { export default {
name: Events.InteractionCreate, name: Events.InteractionCreate,
async execute(interaction: Interaction) { async execute(interaction: Interaction) {
if (interaction.isChatInputCommand()) { if (interaction.isChatInputCommand()) {

View file

@ -1,5 +1,6 @@
import { Events, Message } from "discord.js"; import { Events, Message } from "discord.js";
module.exports = {
export default {
name: Events.MessageCreate, name: Events.MessageCreate,
async execute(message: Message) { async execute(message: Message) {
//console.log(message.content); //console.log(message.content);

View file

@ -1,6 +1,6 @@
import { Events, Client } from "discord.js"; import { Events, Client } from "discord.js";
module.exports = { export default {
name: Events.ClientReady, name: Events.ClientReady,
once: true, once: true,
execute(client: Client) { execute(client: Client) {

View file

@ -9,32 +9,56 @@ const client: Client = new Client({
}) })
client.commands = new Collection(); client.commands = new Collection();
const commands = []; const commands: any[] = [];
const foldersPath = path.join(__dirname, "commands");
const commandFolders = fs.readdirSync(foldersPath);
for (const folder of commandFolders) { async function loadCommands() {
const commandsPath = path.join(foldersPath, folder); const foldersPath = './src/commands';
const commandFiles = fs const commandFolders = fs.readdirSync(foldersPath);
.readdirSync(commandsPath)
.filter((file) => file.endsWith(".ts") || file.endsWith(".js"));
for (const file of commandFiles) { for (const folder of commandFolders) {
const filePath = path.join(commandsPath, file); const commandsPath = `./src/commands/${folder}`;
const command = require(filePath); const commandFiles = fs
if ("data" in command && "execute" in command) { .readdirSync(commandsPath)
client.commands.set(command.data.name, command); .filter((file) => file.endsWith(".ts") || file.endsWith(".js"));
commands.push(command.data.toJSON());
} for (const file of commandFiles) {
else { const filePath = `./commands/${folder}/${file}`;
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`); const command = await import(filePath.replace(".ts", ".js"));
} if ("data" in command.default && "execute" in command.default) {
} client.commands.set(command.default.data.name, command.default);
commands.push(command.default.data.toJSON());
}
else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}
}
async function loadEvents() {
const eventsPath = "./src/events";
const eventFiles = fs
.readdirSync(eventsPath)
.filter((file) => file.endsWith(".ts") || file.endsWith(".js"));
for (const file of eventFiles) {
const filePath = `./events/${file}`;
const event = await import(filePath.replace(".ts", ".js"));
if (event.default.once) {
client.once(event.default.name, (...args) => event.default.execute(...args));
}
else {
client.on(event.default.name, (...args) => event.default.execute(...args));
}
}
} }
const rest = new REST().setToken(process.env.DISCORD_TOKEN ? process.env.DISCORD_TOKEN : ""); const rest = new REST().setToken(process.env.DISCORD_TOKEN ? process.env.DISCORD_TOKEN : "");
(async () => { (async () => {
await loadCommands();
await loadEvents();
try { try {
console.log(`Started refreshing ${commands.length} application (/) commands.`); console.log(`Started refreshing ${commands.length} application (/) commands.`);
@ -49,21 +73,4 @@ const rest = new REST().setToken(process.env.DISCORD_TOKEN ? process.env.DISCORD
} }
})(); })();
const eventsPath = path.join(__dirname, "events");
const eventFiles = fs
.readdirSync(eventsPath)
.filter((file) => file.endsWith(".ts") || file.endsWith(".js"));
for (const file of eventFiles) {
const filePath = path.join(eventsPath, file);
const event = require(filePath);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
}
else {
client.on(event.name, (...args) => event.execute(...args));
}
}
client.login(process.env.DISCORD_TOKEN); client.login(process.env.DISCORD_TOKEN);

View file

@ -1,7 +1,9 @@
{ {
"compilerOptions": { "compilerOptions": {
"target": "es5", "target": "ES5",
"module": "commonjs", "module": "NodeNext",
"moduleResolution": "NodeNext",
"resolveJsonModule": true,
"strict": true, "strict": true,
"outDir": "./dist", "outDir": "./dist",
"skipLibCheck": true, "skipLibCheck": true,