如何修复args连接在一起?

时间:2019-01-02 14:16:48

标签: node.js discord.js

命令为release (link) (what it does)

我不好解释,但我希望它以这种形式出现:

script thread
link //arg1
what it does
gives perks //arg2

但是发生的是它需要第二个:

script thread
link gives perks//arg1
what it does
gives perks //arg2
if (command == "release") {
    if (!message.member.roles.some(r => ["administrator"].includes(r.name))) {
        return message.reply("you are not an admin");
    }
    message.delete().catch(O_o => {
    });
    const channel = message.guild.channels.find("name", "general");
    let arg1 = args.slice(0).join(" ");
    let arg2 = args.slice(1).join(" ");
    const embed = new Discord.RichEmbed()
        .setAuthor("bot", "https://vgy.me/w6DAXP.png")
        .setTitle("script thread")
        .setColor(0x000000)
        .setDescription(arg1)
        .setFooter("bot", "https://vgy.me/w6DAXP.png")
        .setTimestamp()
        .addField("what it does", arg2);
    channel.send(embed)
}

1 个答案:

答案 0 :(得分:1)

slice()方法将数组的一部分的浅表副本返回到从开始到结束(不包括end)选择的新数组对象中。参见Array.slice

因此,就您而言, args = ['links', 'gives perks']

然后,args.slice(0)将返回['links', 'gives perks'],因为0是开始而args.length是结束。这就是为什么arg1是links gives perks

您可以只使用arg1 = args[0]arg2 = args[1]