let replies = ["apple", "aerospace", "smart", "telivision"]
let result = Math.floor((Math.random() * replies.length));
let wordembed = new Discord.MessageEmbed()
.setDescription(replies[result])
.setColor("3788E0")
message.channel.send(wordembed);
每次我用!word的时候,代码都会发送一个随机的单词。但是我怎样才能使它在我用!word 1的时候,它应该发送apple,而在我用!word 3的时候,它应该发送smart
检查第一个参数,并将单词设置为从第一个参数减去1(索引从0开始)。
// User input (arguments)
let args = message.content.substring(1).split(/ +/g);
let replies = ["apple", "aerospace", "smart", "telivision"];
let result = Math.floor((Math.random() * replies.length));
if (args[1]) result = parseInt(args[1]) - 1;
let wordembed = new Discord.MessageEmbed()
.setDescription(replies[result])
.setColor("3788E0");
message.channel.send(wordembed);