a ban command sound simple and i know i could just copy one on the internet but i wanted to make a more specific ban command with arguments like time and looks like this :
const client = new Discord.Client();
client.client;
//message is an array of strings from the message the user send
//and args is everything after the !ban so the mention is args[0]
module.exports = {
name : 'ban',
description : 'bans any user for as long as you want(unit in days)',
execute(message, args) {
if(!message.mentions.users.first()) {
return message.channel.send('please specify a target');
}
// target is who will be banned
const target = message.guild.members.cache.get(message.mentions.users.first().id);
// time is how long will the user be banned (in days) it's mutiplied by 1 to convert it from a stirng to NaN or a number parseInt() works too :)
const time = args[1] * 1;
// checks if there are any arguments
if(args.length === 1) {
message.channel.send('you have not input a reason and a time for the ban');
return;
}
else if(!isNaN(time)) {
// this is where the problem is
try {
target.send('you were banned, dummy accout'); // << this works
target.ban({ reason:args.slice(2).join(' '), days:time }); // << but this doesn't
/* (node:10484) UnhandledPromiseRejectionWarning: DiscordAPIError: Invalid Form Body
delete_message_days: int value should be less than or equal to 7. */
}
catch(error) {
// this code does not execute
console.error(error);
message.reply('there was an issue executing the command');
}
return;
}
// this one works as well only when i dont give a time for the ban (if the if statement above returns false )
else if(typeof args[1] === 'string') {
target.ban({ reason:args.slice(1).join(' ') });
return;
}
},
};
i already set up a command handler and every command i have works fine but on this one i keep getting this error
(node:10484) UnhandledPromiseRejectionWarning: DiscordAPIError: Invalid Form Body
delete_message_days: int value should be less than or equal to 7.
and funny enough, if i typed !ban @user and then anything less than 7 it works fine
question from:
https://stackoverflow.com/questions/65865229/so-i-was-trying-to-make-a-ban-command-using-discord-js-v12-and-i-am-always-getti 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…