Haha-Yes/commands/admin/welcome.js

70 lines
2.8 KiB
JavaScript
Raw Normal View History

2022-08-30 04:14:14 +02:00
import { SlashCommandBuilder, ButtonBuilder, ButtonStyle, ActionRowBuilder, PermissionFlagsBits } from 'discord.js';
import db from '../../models/index.js';
export default {
data: new SlashCommandBuilder()
.setName('welcome')
.setDescription('Set a join message')
.addStringOption(option =>
option.setName('message')
2022-10-31 13:13:09 +01:00
.setDescription('The message you want the bot to say when someone joins the server, in the current channel.')),
2022-08-30 04:14:14 +02:00
category: 'admin',
userPermissions: [PermissionFlagsBits.ManageChannels],
async execute(interaction, args, client) {
const join = await db.joinChannel.findOne({ where: { guildID: interaction.guild.id } });
2022-09-01 01:43:59 +02:00
if (!join && !args.message) {
2022-08-30 04:14:14 +02:00
return interaction.reply({ content: 'You need a message for me to say anything!', ephemeral: true });
}
else if (!join) {
2022-09-01 01:43:59 +02:00
const body = { guildID: interaction.guild.id, channelID: interaction.channel.id, message: args.message };
2022-08-30 04:14:14 +02:00
await db.joinChannel.create(body);
2022-09-01 01:43:59 +02:00
return interaction.reply({ content: `The join message have been set with ${args.message}`, ephemeral: true });
2022-08-30 04:14:14 +02:00
}
const row = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
2022-09-14 11:31:19 +02:00
.setCustomId(`edit${interaction.user.id}`)
2022-08-30 04:14:14 +02:00
.setLabel('Edit')
.setStyle(ButtonStyle.Primary),
)
.addComponents(
new ButtonBuilder()
2022-09-14 11:31:19 +02:00
.setCustomId(`remove${interaction.user.id}`)
2022-08-30 04:14:14 +02:00
.setLabel('Remove')
.setStyle(ButtonStyle.Danger),
)
.addComponents(
new ButtonBuilder()
2022-09-14 11:31:19 +02:00
.setCustomId(`nothing${interaction.user.id}`)
2022-08-30 04:14:14 +02:00
.setLabel('Do nothing')
.setStyle(ButtonStyle.Secondary),
);
await interaction.reply({ content: 'The server already has a message set, do you want to edit it or remove it?', components: [row], ephemeral: true });
2022-09-10 09:35:32 +02:00
client.on('interactionCreate', async (interactionMenu) => {
if (interaction.user !== interactionMenu.user) return;
2022-08-30 04:14:14 +02:00
if (!interactionMenu.isButton) return;
interactionMenu.update({ components: [] });
2022-09-14 11:31:19 +02:00
if (interactionMenu.customId === `edit${interaction.user.id}`) {
2022-09-01 01:43:59 +02:00
if (!args.message) {
2022-08-30 04:14:14 +02:00
return interaction.reply({ content: 'You need to input a message for me to edit!', ephemeral: true });
}
2022-09-01 01:43:59 +02:00
const body = { guildID: interaction.guild.id, channelID: interaction.channel.id, message: args.message };
2022-08-30 04:14:14 +02:00
await db.joinChannel.update(body, { where: { guildID: interaction.guild.id } });
2022-09-01 01:43:59 +02:00
return interaction.editReply({ content: `The join message has been set to ${args.message}`, ephemeral: true });
2022-08-30 04:14:14 +02:00
}
2022-09-14 11:31:19 +02:00
else if (interactionMenu.customId === `remove${interaction.user.id}`) {
2022-08-30 04:14:14 +02:00
db.joinChannel.destroy({ where: { guildID: interaction.guild.id, channelID: interaction.channel.id } });
return interaction.editReply({ content: 'The join message has been deleted.', ephemeral: true });
}
else {
return interaction.editReply({ content: 'Nothing has been changed.', ephemeral: true });
}
});
},
};