如何在discord.js中解析引号中的命令参数?

如何在discord.js中解析引号中的命令参数?,discord.js,Discord.js,标题解释了其中的大部分内容。 我想发出一个轮询命令: const args = message.content.slice(1).trim().split(/ +/g); // trims the args const command = args.shift().toLowerCase(); // finds the actual command const guild = message.guild; client.on("message", async message

标题解释了其中的大部分内容。 我想发出一个轮询命令:

  const args = message.content.slice(1).trim().split(/ +/g); // trims the args
    const command = args.shift().toLowerCase(); // finds the actual command
    const guild = message.guild;
client.on("message", async message => {

   if (command === "poll") {
        const poll = new Discord.RichEmbed().setColor('#' + (0x1000000 + (Math.random()) * 0xffffff).toString(16).substr(1, 6));
        if (args) {
            if (message.member.roles.find(r => r.name === "poller")) {
                var upvote = message.guild.emojis.find(emoji => emoji.name == 'Upvote');
                var downvote = message.guild.emojis.find(emoji => emoji.name == 'Downvote');
                let sendTo = "";
                sendTo+=(args[0]);
                sendTo += (upvote + args[1]);
                sendTo += ("\n\n" + downvote + args[2]);
                message.channel.send(sendTo)
                    .then(function(message) {
                        message.react(guild.emojis.find(emoji => emoji.name === "Upvote"));
                        message.react(guild.emojis.find(emoji => emoji.name === "Downvote"));
                    }).catch(function() {
                        poll.setDescription("Error has occured. Stopping process.");
                        poll.setFooter('Unknown error has occured. Terminating action 000921.');
                        message.channel.send(poll);
                    });
                message.delete().catch(O_o => {});
            }
        } else {
            console.log("Failed");
        }
    }
}
这里的主要问题是,我需要多个词来进行民意调查,但即使有引号,它仍然会像正常一样返回。 例如;投票“测试1”“测试2”“测试3”返回“测试:向上投票:1”:向下投票:“测试”。 我能做些什么来解决这个问题?

您可以使用:

constpollpoptions=message.content.match(/“+?”/g).map(str=>str.replace(/“/g”))
// ;投票“选项1”“选项2”“选项3”
//pollOptions将等于[‘选项1’、‘选项2’、‘选项3’]

代码段示例:

const input='“选项1”和“选项2”,也可能是“选项3”
const updated=input.match(/“+?”/g).map(str=>str.replace(/“/g”))
console.log(更新)//隔离引号中的任何内容