你的意思是,你想回应什么?
您可以调用 Math.random() 函数,获取任何数字,字符串化,然后只需 message.reply(x) 其中x 是您的随机数。
您也可以使用来自 npm 的 random-text-generator 模块,例如回复美国城市或类似:纽约、洛杉矶等。您只需要安装此模块。
记得每次都像这样调用随机函数:
module.exports = {
name: 'random',
description: "random responses",
execute(message, args) {
message.reply(Math.random().toString());
}
}
如果您想从数组中获得随机响应,例如:
cities=["New York","Los Angeles","Chicago","Houston","Phoenix","Philadelphia","San Antonio"]
你可以这样做:
module.exports = {
name: 'random',
description: "random responses",
execute(message, args) {
let cities=["New York","Los Angeles","Chicago","Houston","Phoenix","Philadelphia","San Antonio"]
let randomNbr = Math.floor(Math.random() * 6);
message.reply(cities[randomNbr]);
}
}