我从discord.js开始,我有一个问题。有没有可能生成一个无限的参数?目前我必须使用message.channel.send(${args})
,例如,当我键入$test 1 2时,只会发送1,2不会有帮助。我想为命令$kick生成一个原因,但只有一个参数,第一个参数通常只出现在第一句话中,而不是整个原因,请帮助!
我想你不知道我的意思,我的意思是,参数不应该是一个单词,例如命令:$embed hello-word:(我希望机器人发送:hello-word:(但它发送:hello without word和:(它不一定是hello-word:(它必须是用户给出的单词我希望我写得很清楚,以获得任何帮助,谢谢!
const Discord = require('discord.js');
const client = new Discord.Client();
const config = require('./config.json');
const fs = require('fs');
const prefix = "$";
const RED = "#EC0F0F";
const BLUE = "#1725E7";
const GREEN = "#17E729";
const FIOLET = "#880FEC";
client.once('ready', () => {
console.log('Ready!');
});
client.on('message', async message => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).trim().split(' ');
const command = args.shift().toLowerCase();
console.log(message.content);
if (message.content === `$embed`) {
const embesmess = new Discord.MessageEmbed()
.setTitle(`${args[0]}`)
.setColor(`${GREEN}`)
.setdescription(`HERE I WANT THIS ARGUMENT`)
message.channel.send(embesmess);
}
});
client.login(config.token);
使用类似的东西
if (message.content.startsWith(`$embed`)) {
const embesmess = new Discord.MessageEmbed()
.setTitle(`${args.slice(1).join(" ")}`) //join all arguments besides the first
.setColor(`${GREEN}`)
.setdescription(`HERE I WANT THIS ARGUMENT`)
message.channel.send(embesmess);
}
这将合并除第一个论点外的所有论点。