简体   繁体   中英

how to separate words in 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);
    }
})

but whenever i type !say subscribe today it comes out as subscribe,today can someone please tell me a way to separate the argument so the commas arent there and its more than one word?

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();
});
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);
    }

More on array.join() method here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM