如何制作多字参数。例如禁止或静音的原因。如果我使用 args[2], args[3], args[4], args[5]... 所以它仍然是有限的,如果没有写在那里,它会写“未定义”。所以如果你知道怎么做,我会很高兴得到答案。 :)
const { ReactionCollector } = require("discord.js");
module.exports = {
name: 'ban',
description: "Dočasně zabanuje člena.",
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('Nemáš potřebné permisse!')
.then(msg => {
msg.delete({ timeout: 5000 })
});
return;
} else if(!args[1]){
message.reply('!ban <člen> <délka> (<důvod>)')
.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:'Člen:', value:`${userId}`},
{name:'Udělil:', value:`${author}`},
{name:'Délka:', value:`${ms(ms(args[1]))}`},
{name:'Důvod:', 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:'Člen:', value:`${userId}`},
{name:'Udělil:', value:`<@${botId}>`},
{name:'Důvod:', value:`Ban vypršel.`},
)
.setTimestamp()
channelId.send(unbanEmbed)
}, ms(args[1]));
console.log(chalk.green(`[INFO] /ban/ ${userId.user.username}, ${ms(ms(args[1]))}`));
}else{
message.channel.send('Nemůžeš zabanovat tohoto člena');
console.log(chalk.red(`[ERROR] /ban/ Can not find target`));
}
}
}
答案 0 :(得分:1)
我假设您已正确定义 args
。然后你可以简单地使用
args.join(" ");
用空格分隔每个单词。