Haha-Yes/commands/utility/optout.js

48 lines
1.6 KiB
JavaScript
Raw Normal View History

2022-08-29 20:56:26 +02:00
import { SlashCommandBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } from 'discord.js';
import db from '../../models/index.js';
export default {
data: new SlashCommandBuilder()
.setName('optout')
2022-09-02 09:24:03 +02:00
.setDescription('Opt out of the non commands features.'),
2022-08-29 20:56:26 +02:00
category: 'utility',
async execute(interaction, args, client) {
const isOptOut = await db.optout.findOne({ where: { userID: interaction.user.id } });
if (!isOptOut) {
const body = { userID: interaction.user.id };
await db.optout.create(body);
2022-10-31 13:13:09 +01:00
return await interaction.reply({ content: 'You have successfully been opted out.' });
2022-08-29 20:56:26 +02:00
}
const row = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
2022-09-14 11:31:19 +02:00
.setCustomId(`yes${interaction.user.id}`)
2022-08-29 20:56:26 +02:00
.setLabel('Yes')
.setStyle(ButtonStyle.Primary),
)
.addComponents(
new ButtonBuilder()
2022-09-14 11:31:19 +02:00
.setCustomId(`no${interaction.user.id}`)
2022-08-29 20:56:26 +02:00
.setLabel('No')
.setStyle(ButtonStyle.Danger),
);
2022-10-31 13:13:09 +01:00
await interaction.reply({ content: 'You are already opted out, do you wish to opt in?', components: [row] });
2022-08-29 20:56:26 +02:00
2022-09-10 09:35:32 +02:00
client.on('interactionCreate', async (interactionMenu) => {
if (interaction.user !== interactionMenu.user) return;
2022-08-29 20:56:26 +02:00
if (!interactionMenu.isButton) return;
interactionMenu.update({ components: [] });
2022-09-14 11:31:19 +02:00
if (interactionMenu.customId === `yes${interaction.user.id}`) {
2022-08-29 20:56:26 +02:00
await db.optout.destroy({ where: { userID: interaction.user.id } });
2022-10-31 13:13:09 +01:00
return interaction.editReply('You have successfully been opted in');
2022-08-29 20:56:26 +02:00
}
else {
return interaction.editReply('Nothing has been changed.');
}
});
},
};