Version Estable
This commit is contained in:
53
src/events/interactionCreate.ts
Normal file
53
src/events/interactionCreate.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { bot } from "../main";
|
||||
import type { BaseInteraction } from "discord.js";
|
||||
import { Events } from "discord.js";
|
||||
import { redis } from "../core/redis";
|
||||
import { commands } from "../core/loader";
|
||||
import { buttons, modals, selectmenus } from "../core/components";
|
||||
|
||||
bot.on(Events.InteractionCreate, async (interaction: BaseInteraction) => {
|
||||
try {
|
||||
// 🔹 Slash commands
|
||||
if (interaction.isChatInputCommand()) {
|
||||
const cmd = commands.get(interaction.commandName);
|
||||
if (!cmd) return;
|
||||
|
||||
const cooldown = Math.floor(Number(cmd.cooldown) || 0);
|
||||
|
||||
if (cooldown > 0) {
|
||||
const key = `cooldown:${cmd.name}:${interaction.user.id}`;
|
||||
const ttl = await redis.ttl(key);
|
||||
if (ttl > 0) {
|
||||
return interaction.reply(`⏳ Espera ${ttl}s antes de volver a usar **${cmd.name}**.`);
|
||||
}
|
||||
await redis.set(key, "1", { EX: cooldown });
|
||||
}
|
||||
|
||||
await cmd.run(interaction, bot);
|
||||
}
|
||||
|
||||
// 🔹 Botones
|
||||
if (interaction.isButton()) {
|
||||
//@ts-ignore
|
||||
const btn = buttons.get(interaction.customId);
|
||||
if (btn) await btn.run(interaction, bot);
|
||||
}
|
||||
|
||||
// 🔹 Select menus
|
||||
if (interaction.isStringSelectMenu()) {
|
||||
const menu = selectmenus.get(interaction.customId);
|
||||
if (menu) await menu.run(interaction, bot);
|
||||
}
|
||||
|
||||
// 🔹 Modales
|
||||
if (interaction.isModalSubmit()) {
|
||||
const modal = modals.get(interaction.customId);
|
||||
if (modal) await modal.run(interaction, bot);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
if (interaction.isRepliable()) {
|
||||
await interaction.reply({ content: "❌ Hubo un error ejecutando la interacción.", ephemeral: true });
|
||||
}
|
||||
}
|
||||
});
|
||||
40
src/events/messageCreate.ts
Normal file
40
src/events/messageCreate.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import {bot} from "../main";
|
||||
import {Events} from "discord.js";
|
||||
import {redis} from "../core/redis";
|
||||
import {commands} from "../core/loader";
|
||||
|
||||
|
||||
bot.on(Events.MessageCreate, async (message) => {
|
||||
if (message.author.bot) return;
|
||||
const server = await bot.prisma.guild.findFirst({ where: { id: message.guild!.id } }) || "!";
|
||||
const PREFIX = server.prefix
|
||||
if (!message.content.startsWith(PREFIX)) return;
|
||||
|
||||
const [cmdName, ...args] = message.content.slice(PREFIX.length).trim().split(/\s+/);
|
||||
console.log(cmdName);
|
||||
const command = commands.get(cmdName);
|
||||
if (!command) return;
|
||||
|
||||
const cooldown = Math.floor(Number(command.cooldown) || 0);
|
||||
|
||||
if (cooldown > 0) {
|
||||
const key = `cooldown:${command.name}:${message.author.id}`;
|
||||
const ttl = await redis.ttl(key);
|
||||
console.log(`Key: ${key}, TTL: ${ttl}`);
|
||||
|
||||
if (ttl > 0) {
|
||||
return message.reply(`⏳ Espera ${ttl}s antes de volver a usar **${command.name}**.`);
|
||||
}
|
||||
|
||||
// SET con expiración correcta para redis v4+
|
||||
await redis.set(key, "1", { EX: cooldown });
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
await command.run(message, args, message.client);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
await message.reply("❌ Hubo un error ejecutando el comando.");
|
||||
}
|
||||
})
|
||||
6
src/events/ready.ts
Normal file
6
src/events/ready.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import {bot} from "../main";
|
||||
import {Events} from "discord.js";
|
||||
|
||||
bot.on(Events.ClientReady, () => {
|
||||
console.log("Ready!");
|
||||
})
|
||||
Reference in New Issue
Block a user