Is there a way to create multi-word arguments, such as reasons for bans or mutes? Currently, I am using args[2], args[3], args[4], args[5]... but this approach is limited and if nothing is written in those arguments, it will display "undefined". If you know how to achieve this, I would greatly appreciate your answer. :)
const { ReactionCollector } = require("discord.js");
module.exports = {
name: 'ban',
description: "Temporarily bans a member.",
async execute(message, args, Discord, client, chalk, ms){
await message.channel.messages.fetch({limit: 1}).then(messages =>{
message.channel.bulkDelete(messages);
});
const channelId = client.channels.cache.get('802649418087530537');
const author = message.author;
const userName = message.mentions.users.first();
if(!message.member.permissions.has("BAN_MEMBERS")){
message.reply('You do not have the necessary permissions!')
.then(msg => {
msg.delete({ timeout: 5000 })
});
return;
} else if(!args[1]){
message.reply('!ban <member> <duration> (<reason>)')
.then(msg => {
msg.delete({ timeout: 5000 })
});
console.log(chalk.red('[ERROR] Missing args[1]'));
return;
}
if(userName){
const userId = message.guild.members.cache.get(userName.id);
const botId = '799652033509457940';
userId.ban();
const banEmbed = new Discord.MessageEmbed()
.setColor('#a81919')
.setTitle('Ban')
.addFields(
{name:'Member:', value:`${userId}`},
{name:'Issued by:', value:`${author}`},
{name:'Duration:', value:`${ms(ms(args[1]))}`},
{name:'Reason:', value:`${args[2]}`},
)
.setTimestamp()
channelId.send(banEmbed)
setTimeout(function () {
message.guild.members.unban(userId);
const unbanEmbed = new Discord.MessageEmbed()
.setColor('#25a819')
.setTitle('Unban')
.addFields(
{name:'Member:', value:`${userId}`},
{name:'Issued by:', value:`<@${botId}>`},
{name:'Reason:', value:`Ban expired.`},
)
.setTimestamp()
channelId.send(unbanEmbed)
}, ms(args[1]));
console.log(chalk.green(`[INFO] /ban/ ${userId.user.username}, ${ms(ms(args[1]))}`));
}else{
message.channel.send('You cannot ban this member');
console.log(chalk.red(`[ERROR] /ban/ Can not find target`));
}
}
}