我正在尝试创建Wyr,以便用户可以选择表情符号。我使用了下面代码的变体,但无法将消息发送到机器人发送的消息。
我确实尝试过return();但是也许我做错了,因为它没有用。这是我当前正在使用的代码。
module.exports = {
name: "wyr",
description: "Would You Rather?",
execute(message) {
message.channel.send(dowyr());
function dowyr() {
var theWyr = ["Would you rather...\n\:a: Have the ability to go to the future?\n\:b: Have the ability to go to the past?"];
return wry = theWyr[Math.floor(Math.random() * theWyr.length)];
message.react("?️");
message.react("?️");
}
},
};
答案 0 :(得分:1)
message
是用户发送的消息,因此您需要将.react()
方法指向漫游器发送的消息,您可以为此使用.then()
。
因此您的代码应为:
module.exports = {
name: "wyr",
description: "Would You Rather?",
execute(message) {
message.channel.send(dowyr()).then((msg) => {
msg.react("?️");
msg.react("?️");
});
function dowyr() {
var theWyr = ["Would you rather...\n\:a: Have the ability to go to the future?\n\:b: Have the ability to go to the past?"];
return wry = theWyr[Math.floor(Math.random() * theWyr.length)];
}
},
};