feat(commands/moderation): adding the option to silent notification

This commit is contained in:
Raphael 2025-11-15 00:38:13 +01:00 committed by Raphaël
parent 9b770235f0
commit 2a0111efea

View file

@ -18,6 +18,11 @@ export default {
.setName('channel') .setName('channel')
.setDescription('Choose the channel you want to renew') .setDescription('Choose the channel you want to renew')
.addChannelTypes(ChannelType.GuildText), .addChannelTypes(ChannelType.GuildText),
)
.addBooleanOption((opt) =>
opt
.setName('silent')
.setDescription('Choose if a notification will be send'),
), ),
async execute(interaction: ChatInputCommandInteraction) { async execute(interaction: ChatInputCommandInteraction) {
if (!interaction.guild) { if (!interaction.guild) {
@ -34,6 +39,7 @@ export default {
}); });
return; return;
} }
const notification: boolean = interaction.options.getBoolean('silent') ?? false;
const oldChannel = (interaction.options.getChannel('channel') ?? const oldChannel = (interaction.options.getChannel('channel') ??
interaction.channel) as TextChannel | null; interaction.channel) as TextChannel | null;
if (!oldChannel) { if (!oldChannel) {
@ -46,18 +52,24 @@ export default {
const pos: number = oldChannel.position; const pos: number = oldChannel.position;
try { try {
const newchannel = await oldChannel.clone(); const newChannel = await oldChannel.clone();
await newchannel.setPosition(pos); await newChannel.setPosition(pos);
const fetchedChannel = await interaction.client.channels.fetch( const fetchedChannel = await interaction.client.channels.fetch(
newchannel.id, newChannel.id,
); );
if ( if (
fetchedChannel && !notification && fetchedChannel &&
fetchedChannel.type === ChannelType.GuildText && fetchedChannel.type === ChannelType.GuildText &&
typeof (fetchedChannel as TextChannel).send === 'function' typeof (fetchedChannel as TextChannel).send === 'function'
) { ) {
await (fetchedChannel as TextChannel).send({ await (fetchedChannel as TextChannel).send({
content: `${emoji.answer.yes} | ${newchannel.toString()} has been nuked by \`${interaction.user.username}\``, content: `${emoji.answer.yes} | ${newChannel.toString()} has been nuked by \`${interaction.user.username}\``,
});
}
if (interaction.channel != oldChannel) {
await interaction.reply({
content: `${emoji.answer.yes} | ${newChannel.toString()} is now created.`,
flags: MessageFlags.Ephemeral,
}); });
} }
await oldChannel.delete(); await oldChannel.delete();