eximiabots-radiox/src/client/events/interactionCreate.ts
Christer Warén 973cd00c82 Fix typings
2024-09-30 13:22:31 +03:00

46 lines
1.8 KiB
TypeScript

import { ChannelType, Interaction, PermissionFlagsBits } from "discord.js";
import RadioClient from "../../Client";
export default function interactionCreate(client: RadioClient, interaction: Interaction) {
if(!(interaction.isButton()) && !(interaction.isChatInputCommand()) && !(interaction.isStringSelectMenu())) return;
if(interaction.channel?.type == ChannelType.DM || interaction.channel?.type == ChannelType.GroupDM) return;
const permissions = interaction.channel?.permissionsFor(interaction.client.user);
if (!permissions?.has(PermissionFlagsBits.ViewChannel)) return;
if (!permissions?.has(PermissionFlagsBits.EmbedLinks)) return interaction.reply({
content: client.messages.emojis["error"] + client.messages.noPermsEmbed,
ephemeral: true
});
if(interaction.isChatInputCommand()){
const commandName = interaction.commandName;
const command = client.commands.get(commandName);
if (!command) return;
try {
command.execute(interaction, client);
} catch (error) {
interaction.reply({
content: client.messages.emojis["error"] + client.messages.runningCommandFailed,
ephemeral: true
});
console.error(error);
}
} else if (interaction.isStringSelectMenu() || interaction.isButton()){
const commandName = interaction.customId;
const command = client.commands.get(commandName);
if (!command) return;
try {
command.execute(interaction, client, command);
} catch (error) {
interaction.reply({
content: client.messages.emojis["error"] + client.messages.runningCommandFailed,
ephemeral: true
});
console.error(error);
}
}
}