簡體   English   中英

如何在 arguments (discord.js) 中分隔單詞

[英]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);
    }
})

但是每當我輸入!say subscribe today時,它就會顯示為subscribe,today有人可以告訴我一種分隔參數的方法,以便逗號不存在並且它不止一個詞嗎?

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

更多關於 array.join() 方法here

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM