I have this TypeScript code for blocking someone from ModMail via a slash command. Although the slash command gives the option to add a time, the block ends up being permanent, even if a duration is added. Please help. Thank you.
import { Command } from "../../class/Command";
import { SlashCommandBuilder } from "discord.js";
import { errorEmbed, successEmbed } from "../../util/functions";
import { toMs, fromMs } from 'ms-typescript';
export default new Command({
command_data: new SlashCommandBuilder()
.setName('ban')
.setDescription('Ban a guild member from using the ModMail system.')
.addUserOption((opt) =>
opt.setName('user')
.setDescription('The user to ban.')
.setRequired(true)
)
.addStringOption((opt) =>
opt.setName('duration')
.setDescription('The duration of the ban. (use s, m, d, w... etc.)')
.setRequired(false)
)
.addStringOption((opt) =>
opt.setName('reason')
.setDescription('The reason for the ban.')
.setRequired(false)
)
.setDMPermission(false)
.toJSON(),
run: async (client, interaction, args) => {
const user = args.getUser('user');
const time = toMs(args.getString('duration') ?? '0');
const reason = args.getString('reason') || 'No reason was provided';
let data_check = client.bans_db.get(user.id);
if (data_check) {
await interaction.reply({
embeds: [
errorEmbed('The user is already banned.')
],
ephemeral: true
});
return;
};
client.bans_db.set(user.id, time && reason);
await interaction.reply({
embeds: [
successEmbed('The user <@' + user.id + '> has been successfully banned')
]
});
return;
}
});