如何在arguments中分隔单词(discord.js)


client.on('message', message => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).trim().split(' ');
const command = args.shift().toLowerCase();
if (command === 'say') {
if (!args.length) {
return message.channel.send(`Please tell the bot what to say, ${message.author}`);
}

const { Client, MessageEmbed } = require('discord.js');
const embed = new MessageEmbed()
.setTitle(`${args}`)
.setColor('RED')
message.channel.send(embed);
}
})

但每当我键入!say subscribe today时,它就会显示为subscribe,today有人能告诉我一种方法来分开论点,这样逗号就不存在了,而且它不止一个词吗?

if (command === 'say') {
if (!args.length) {
return message.channel.send(`Please tell the bot what to say, ${message.author}`);
}
let text = args.join(' '); //Join the array of strings with a space to create a text to send
const { Client, MessageEmbed } = require('discord.js');
const embed = new MessageEmbed()
.setTitle(text)
.setColor('RED')
message.channel.send(embed);
}

更多关于array.join((方法的信息

const Discord = require('discord.js');
const client = new Discord.Client();
const prefix = '!';
client.on('message', (message) => {
let args = message.content.substring(0, prefix.length).split(' ');
let command = args.shift();
});

最新更新