[英]Discord.js “channel” not defined error message
我最近对使用 Javascript 和 node.js 制作 discord 机器人产生了兴趣。 我正在尝试制作一个旋转虚拟“彩票”的命令,并发送一条消息告诉用户他们是否收到任何东西。 (这是我的代码:)
`
function lotteryCommand(arguments, receivedMessage){
/*note: receivedMessage is defined as the command (for my bot, it's e!spin)
and arguments is the part following the command (for this particular bit of code,
it's merits, so the user sends "e!spin merits")*/
if (arguments == "merits"){
setTimeout(randomlottery1, 1000);
}
else{receivedMessage.channel.send("Message here")}
}
这是另一个 function。 这是它停止工作的地方
function randomlottery1(arguments, receivedMessage){
let respond;
let responses = [
//some random phrases here
]
respond = responses[Math.floor(Math.random() * responses.length)]
receivedMessage.channel.send(respond)
}
由于某种原因,我无法理解,它第二次在randomlottery1
function 中无法识别receivedMessage.channel.send
消息.channel.send 中的channel
,但它识别了代码中前面的命令。 我在这里做错了什么吗? 谢谢。
我认为您的问题是您没有将任何参数传递给您的 function,您可以通过以下操作轻松修复它:
function lotteryCommand(arguments, receivedMessage){
/*note: receivedMessage is defined as the command (for my bot, it's e!spin)
and arguments is the part following the command (for this particular bit of code,
it's merits, so the user sends "e!spin merits")*/
if (arguments == "merits"){
// dont forget to pass in the required parameters while executing your function (parameter1, parameter2)
setTimeout(randomlottery1(arguments, receivedMessage), 1000);
}
else{receivedMessage.channel.send("Message here")}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.