gateway-bot / src /commands /setup.js
Archnemix's picture
Upload 28 files
9b7ecf4 verified
Raw History Blame Contribute Delete
5.66 kB
import {
SlashCommandBuilder,
ChannelType,
PermissionFlagsBits,
EmbedBuilder,
MessageFlags,
} from 'discord.js'
import { loadGuildConfig, setGuildConfig } from '../storage/cache.js'
export const data = new SlashCommandBuilder()
.setName('setup')
.setDescription('Configure the bot for this server')
.addSubcommand((sub) =>
sub
.setName('channels')
.setDescription('Set the welcome and leave channels')
.addChannelOption((opt) =>
opt
.setName('welcome')
.setDescription('Channel to post welcome messages in')
.addChannelTypes(ChannelType.GuildText)
.setRequired(true)
)
.addChannelOption((opt) =>
opt
.setName('leave')
.setDescription('Channel to post leave messages in')
.addChannelTypes(ChannelType.GuildText)
.setRequired(true)
)
)
.addSubcommand((sub) =>
sub
.setName('autorole-add')
.setDescription('Add a role to be assigned when a member joins')
.addRoleOption((opt) =>
opt
.setName('role')
.setDescription('Role to auto-assign')
.setRequired(true)
)
)
.addSubcommand((sub) =>
sub
.setName('autorole-remove')
.setDescription('Remove a role from auto-assign list')
.addRoleOption((opt) =>
opt
.setName('role')
.setDescription('Role to remove')
.setRequired(true)
)
)
.addSubcommand((sub) =>
sub
.setName('autorole-list')
.setDescription('Show all currently configured auto-assign roles')
)
.addSubcommand((sub) =>
sub
.setName('dm')
.setDescription('Toggle welcome DM on or off')
.addBooleanOption((opt) =>
opt
.setName('enabled')
.setDescription('Send a DM to new members when they join')
.setRequired(true)
)
)
export async function execute(interaction) {
// All subcommands require Manage Server
if (!interaction.memberPermissions.has(PermissionFlagsBits.ManageGuild)) {
await interaction.reply({
content: 'You need Manage Server permission to use this command.',
flags: MessageFlags.Ephemeral,
})
return
}
const sub = interaction.options.getSubcommand()
const guildId = interaction.guildId
if (sub === 'channels') {
const welcome = interaction.options.getChannel('welcome')
const leave = interaction.options.getChannel('leave')
const config = await loadGuildConfig(guildId)
config.welcomeChannelId = welcome.id
config.leaveChannelId = leave.id
await setGuildConfig(guildId, config)
const embed = new EmbedBuilder()
.setColor(0x5865f2)
.setTitle('Channels Updated')
.setDescription(
`✅ Welcome channel set to ${welcome}\n✅ Leave channel set to ${leave}`
)
await interaction.reply({ embeds: [embed], flags: MessageFlags.Ephemeral })
return
}
if (sub === 'autorole-add') {
const role = interaction.options.getRole('role')
const config = await loadGuildConfig(guildId)
if (config.autoRoles.includes(role.id)) {
await interaction.reply({
content: 'That role is already in the auto-assign list.',
flags: MessageFlags.Ephemeral,
})
return
}
config.autoRoles.push(role.id)
await setGuildConfig(guildId, config)
const embed = new EmbedBuilder()
.setColor(0x57f287)
.setTitle('Auto-Role Added')
.setDescription(`New members will now receive <@&${role.id}>`)
await interaction.reply({ embeds: [embed], flags: MessageFlags.Ephemeral })
return
}
if (sub === 'autorole-remove') {
const role = interaction.options.getRole('role')
const config = await loadGuildConfig(guildId)
if (!config.autoRoles.includes(role.id)) {
await interaction.reply({
content: 'That role is not in the list.',
flags: MessageFlags.Ephemeral,
})
return
}
config.autoRoles = config.autoRoles.filter((id) => id !== role.id)
await setGuildConfig(guildId, config)
const embed = new EmbedBuilder()
.setColor(0xed4245)
.setTitle('Auto-Role Removed')
.setDescription(`<@&${role.id}> will no longer be assigned to new members`)
await interaction.reply({ embeds: [embed], flags: MessageFlags.Ephemeral })
return
}
if (sub === 'autorole-list') {
const config = await loadGuildConfig(guildId)
if (!config.autoRoles.length) {
await interaction.reply({
content: 'No auto-roles configured.',
flags: MessageFlags.Ephemeral,
})
return
}
const roleList = config.autoRoles.map((id) => `<@&${id}>`).join('\n')
const embed = new EmbedBuilder()
.setColor(0x5865f2)
.setTitle('Auto-Assign Roles')
.setDescription(roleList)
await interaction.reply({ embeds: [embed], flags: MessageFlags.Ephemeral })
return
}
if (sub === 'dm') {
const enabled = interaction.options.getBoolean('enabled')
const config = await loadGuildConfig(guildId)
config.dmEnabled = enabled
await setGuildConfig(guildId, config)
const embed = new EmbedBuilder()
.setColor(enabled ? 0x57f287 : 0xed4245)
.setTitle('Welcome DM Updated')
.setDescription(
`Welcome DMs are now **${enabled ? 'enabled' : 'disabled'}**`
)
await interaction.reply({ embeds: [embed], flags: MessageFlags.Ephemeral })
return
}
}