TypeScript Logical Error Not Syntax Error

So, I have a ModMail bot made in TypeScript, and I have a slash command that blocks the user from D.M.'ing the bot any further. The problem is, when inputting the time/duration for how long the block wants to be in the slash command, the bot disregards it by having the block be permanent. Please help. The code is below. Thanks.
17 Replies
d.js toolkit
d.js toolkit12mo ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
sky
sky12mo ago
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';

if (time <= 0 || time > 2419200000) {
await interaction.reply({
content: 'The time must be between **1 second** and **28 days**.'
});

return;
};

const member = interaction.guild?.members.cache.get(user.id);

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;
};
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';

if (time <= 0 || time > 2419200000) {
await interaction.reply({
content: 'The time must be between **1 second** and **28 days**.'
});

return;
};

const member = interaction.guild?.members.cache.get(user.id);

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;
}
});
client.bans_db.set(user.id, time && reason);

await interaction.reply({
embeds: [
successEmbed('The user <@' + user.id + '> has been successfully banned')
]
});

return;
}
});
Message regarding the above code is sent above "d.js tookit's" message.
Unknown User
Unknown User12mo ago
Message Not Public
Sign In & Join Server To View
sky
sky12mo ago
I already informed you that I do not know how to do so.
Unknown User
Unknown User12mo ago
Message Not Public
Sign In & Join Server To View
sky
sky12mo ago
Correct!
Unknown User
Unknown User12mo ago
Message Not Public
Sign In & Join Server To View
sky
sky12mo ago
Gee! It's all clear to me, now! Thanks for your condescending remark that has made it utterly clear to me on how to proceed! me: go fly a plane you: i don't know how me: that's basic flight how logical
duck
duck12mo ago
if you don't know how to call a function in javascript (despite the fact that you already do multiple times) I would heavily suggest brushing up on the basics before continuing #resources / #other-js-ts please also take note of #rules 3
sky
sky12mo ago
I did not say I don't know how to call a function. I'm saying I do not know how to implement "setTimeout." This is literally my first day ever hearing about it.
Unknown User
Unknown User12mo ago
Message Not Public
Sign In & Join Server To View
sky
sky12mo ago
Yes. No, because there is absolutely no example on that website that is in regards of Discord's API.
Unknown User
Unknown User12mo ago
Message Not Public
Sign In & Join Server To View
sky
sky12mo ago
I know.
duck
duck12mo ago
which is to say, as explained on that page, you can pass whatever function you want to setTimeout just put the code you want to execute after the timeout in that function
sky
sky12mo ago
The code that I sent above I found off a tutorial, so I do not know how to proceed. I am a beginner.
duck
duck12mo ago
then you should learn the basics before continuing #resources please also take note of #rules 3