Spaces:
Sleeping
Sleeping
File size: 1,710 Bytes
e903adb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | import { SlashCommandBuilder, EmbedBuilder } from 'discord.js'
import { initGuildConfig } from '../storage/cache.js'
export const data = new SlashCommandBuilder()
.setName('reset')
.setDescription('Reset all bot settings for this server to defaults')
.addSubcommand((sub) =>
sub
.setName('confirm')
.setDescription('Confirm the reset — this cannot be undone')
.addStringOption((opt) =>
opt
.setName('confirmation')
.setDescription('Type RESET to confirm')
.setRequired(true)
)
)
export async function execute(interaction, res) {
const perms = BigInt(interaction.member.permissions)
const MANAGE_GUILD = 32n
const ADMINISTRATOR = 8n
if (!(perms & MANAGE_GUILD) || !(perms & ADMINISTRATOR)) {
return res.json({
type: 4,
data: {
content: 'You need both Manage Server and Administrator permissions to use this command.',
flags: 64,
},
})
}
const sub = interaction.data.options[0].name
if (sub === 'confirm') {
const confirmation = (interaction.data.options[0].options ?? []).find(
(o) => o.name === 'confirmation'
)?.value
if (confirmation !== 'RESET') {
return res.json({
type: 4,
data: { content: 'You must type RESET exactly to confirm.', flags: 64 },
})
}
await initGuildConfig(interaction.guild_id)
const embed = new EmbedBuilder()
.setColor(0xed4245)
.setTitle('Server Config Reset')
.setDescription(
'All settings have been reset to defaults.\nYou will need to run /setup channels again.'
)
return res.json({ type: 4, data: { embeds: [embed.toJSON()], flags: 64 } })
}
}
|