1
0
mirror of https://github.com/toast-ts/Daggerbot-TS.git synced 2024-09-29 16:30:59 -04:00
Daggerbot-TS/src/events/interactionCreate.ts

50 lines
3.1 KiB
TypeScript
Raw Normal View History

import Discord from 'discord.js';
2023-04-14 06:47:58 -04:00
import TClient from '../client.js';
export default {
2023-08-14 10:36:29 -04:00
async run(client:TClient, interaction:Discord.BaseInteraction){
2023-02-13 02:37:23 -05:00
if (!interaction.inGuild() || !interaction.inCachedGuild()) return;
if (interaction.isChatInputCommand()){
const commandFile = client.commands.get(interaction.commandName);
2023-08-14 10:36:29 -04:00
console.log(client.logTime(), `${interaction.user.username} used /${interaction.commandName} ${interaction.options.getSubcommandGroup(false) ?? ''} ${interaction.options.getSubcommand(false) ?? ''} in #${interaction.channel.name}`);
if (!client.config.botSwitches.commands && !client.config.whitelist.includes(interaction.user.id)) return interaction.reply({content: `I am currently operating in development mode.\nPlease notify <@${client.config.whitelist[0]}> if this is a mistake.`, ephemeral: true});
2023-02-13 02:37:23 -05:00
if (commandFile){
try{
2023-04-14 06:47:58 -04:00
commandFile.command.default.run(client, interaction);
2023-08-14 10:36:29 -04:00
commandFile.command.default.autocomplete ? commandFile.command.default.autocomplete(interaction) : undefined;
2023-03-05 05:04:10 -05:00
commandFile.uses ? commandFile.uses++ : commandFile.uses = 1;
2023-02-13 02:37:23 -05:00
} catch (error){
2023-03-31 04:56:01 -04:00
console.log(`An error occurred while running command "${interaction.commandName} ${interaction.options.getSubcommand(false) ?? ''}"`, error, error.stack);
return interaction.reply('An error occurred while executing that command.');
}
2023-02-13 02:37:23 -05:00
}
2023-08-14 10:36:29 -04:00
} else if (interaction.isAutocomplete()){
try {
await client.commands.get(interaction.commandName).command.default.autocomplete(client, interaction);
2023-08-14 10:36:29 -04:00
} catch (error){
return console.log('An error occurred while running autocomplete:\n', error)
}
2023-05-02 17:35:43 -04:00
} else if (interaction.isButton()){
if (interaction.customId.startsWith('reaction-') && client.config.botSwitches.buttonRoles){
const RoleID = interaction.customId.replace('reaction-','');
// Note: This is just a temporary "permanent" fix for the issue of people having both roles and less work for the mods.
let buttonRoleBlocked = 'Cannot have both roles! - Button Role';
if (interaction.member.roles.cache.has('1149139369433776269') && RoleID === '1149139583729160325') {
interaction.member.roles.add('1149139583729160325', buttonRoleBlocked);
interaction.member.roles.remove('1149139369433776269', buttonRoleBlocked);
} else if (interaction.member.roles.cache.has('1149139583729160325') && RoleID === '1149139369433776269') {
interaction.member.roles.add('1149139369433776269', buttonRoleBlocked);
interaction.member.roles.remove('1149139583729160325', buttonRoleBlocked);
}
2023-05-02 17:35:43 -04:00
if (interaction.member.roles.cache.has(RoleID)){
interaction.member.roles.remove(RoleID, 'Button Role');
2023-05-02 17:35:43 -04:00
interaction.reply({content: `You have been removed from <@&${RoleID}>`, ephemeral: true})
} else {
interaction.member.roles.add(RoleID, 'Button Role');
2023-05-02 17:35:43 -04:00
interaction.reply({content: `You have been added to <@&${RoleID}>`, ephemeral: true})
}
} else console.log(client.logTime(), `Button pressed at ${interaction.message.url}`);
}
2023-02-13 02:37:23 -05:00
}
2023-03-05 05:04:10 -05:00
}