Haha-Yes/commands/admin/autoresponse.js

49 lines
1.8 KiB
JavaScript
Raw Normal View History

2022-08-29 21:06:18 +02:00
import { SlashCommandBuilder, ButtonBuilder, ButtonStyle, ActionRowBuilder, PermissionFlagsBits } from 'discord.js';
2022-08-29 20:37:59 +02:00
import db from '../../models/index.js';
export default {
data: new SlashCommandBuilder()
.setName('autoresponse')
.setDescription('Enable or disable autoresponse'),
category: 'admin',
2022-08-29 21:06:18 +02:00
userPermissions: [PermissionFlagsBits.ManageMessages],
2022-08-29 20:37:59 +02:00
async execute(interaction, args, client) {
const autoresponseStat = await db.autoresponseStat.findOne({ where: { serverID: interaction.guild.id } });
if (autoresponseStat.stat !== 'enable') {
const body = { serverID: interaction.guild.id, stat: 'enable' };
await db.autoresponseStat.create(body);
return await interaction.reply({ content: 'Autoresponse has been enabled.', ephemeral: true });
2022-08-29 20:37:59 +02:00
}
const row = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId('yes')
.setLabel('Yes')
.setStyle(ButtonStyle.Primary),
)
.addComponents(
new ButtonBuilder()
.setCustomId('no')
.setLabel('No')
.setStyle(ButtonStyle.Danger),
);
await interaction.reply({ content: 'Autoresponse is already enabled, do you wish to disable it?', components: [row], ephemeral: true });
2022-08-29 20:37:59 +02:00
client.once('interactionCreate', async (interactionMenu) => {
if (!interactionMenu.isButton) return;
interactionMenu.update({ components: [] });
if (interactionMenu.customId === 'yes') {
const body = { serverID: interaction.guild.id, stat: 'disable' };
await db.autoresponseStat.update(body, { where: { serverID: interaction.guild.id } });
return interaction.editReply({ content: 'Auto response has been disabled.', ephemeral: true });
2022-08-29 20:37:59 +02:00
}
else {
return interaction.editReply({ content: 'Nothing has been changed.', ephemeral: true });
2022-08-29 20:37:59 +02:00
}
});
},
};