Files
ECS-FullStack/discord-bot/commands/setup-welcome.js

64 lines
2.1 KiB
JavaScript

const { SlashCommandBuilder } = require('discord.js');
const { readDb, writeDb } = require('../../backend/db.js');
module.exports = {
name: 'config-welcome',
description: 'Configure the welcome message for this server.',
enabled: true,
builder: new SlashCommandBuilder()
.setName('config-welcome')
.setDescription('Configure the welcome message for this server.')
.addSubcommand(subcommand =>
subcommand
.setName('set-channel')
.setDescription('Set the channel for welcome messages.')
.addChannelOption(option =>
option.setName('channel')
.setDescription('The channel to send welcome messages to.')
.setRequired(true)
)
)
.addSubcommand(subcommand =>
subcommand
.setName('set-message')
.setDescription('Set the welcome message.')
.addStringOption(option =>
option.setName('message')
.setDescription('The welcome message. Use {user} for username mention and {server} for server name.')
.setRequired(true)
)
)
.addSubcommand(subcommand =>
subcommand
.setName('disable')
.setDescription('Disable welcome messages.')
),
async execute(interaction) {
const db = readDb();
const guildId = interaction.guildId;
const subcommand = interaction.options.getSubcommand();
if (!db[guildId]) {
db[guildId] = {};
}
if (subcommand === 'set-channel') {
const channel = interaction.options.getChannel('channel');
db[guildId].welcomeChannel = channel.id;
db[guildId].welcomeEnabled = true;
writeDb(db);
await interaction.reply(`Welcome channel set to ${channel}.`);
} else if (subcommand === 'set-message') {
const message = interaction.options.getString('message');
db[guildId].welcomeMessage = message;
db[guildId].welcomeEnabled = true;
writeDb(db);
await interaction.reply(`Welcome message set to: "${message}"`);
} else if (subcommand === 'disable') {
db[guildId].welcomeEnabled = false;
writeDb(db);
await interaction.reply('Welcome messages disabled.');
}
},
};