Files
BluBot/commands/utility/auto-welcome.js
2025-06-21 15:13:58 -05:00

47 lines
1.3 KiB
JavaScript

const {
Client,
Interaction,
ApplicationCommandOptionType,
PermissionFlagsBits,
SlashCommandBuilder,
} = require("discord.js");
const db = require("../../db");
module.exports = {
data: new SlashCommandBuilder()
.setName("autowelcome")
.setDescription("Enable or disable auto-welcome messages.")
.addChannelOption((option) =>
option
.setName("channel")
.setDescription(
"Channel Id to send welcome messages (required when enabling)"
)
.setRequired(false)
)
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator),
async execute(interaction) {
const channelId = interaction.options.getChannel("channel");
const guildId = interaction.guild.id;
if (channelId) {
await db.query(
`INSERT INTO auto_welcome (guild_id, channel_id, enabled)
VALUES ($1, $2, $3)
ON CONFLICT (guild_id) DO UPDATE SET channel_id = $2, enabled = $3`,
[guildId, channelId.id, true]
);
return interaction.reply(
`Auto-welcome enabled! Messages will be sent to <#${channelId.id}>.`
);
} else {
await db.query(
`UPDATE auto_welcome SET enabled = $1 WHERE guild_id = $2`,
[false, guildId]
);
return interaction.reply("Auto-welcome has been disabled.");
}
},
};