【发布时间】:2020-11-25 00:48:10
【问题描述】:
我制作了一个不和谐机器人,并在不和谐服务器上寻求有关此代码的一些帮助。他们建议在这里问。
这是原始代码
if(msg.content.toLowerCase() === "yandev, buy something"){
var Patreon = Math.random();
if (Patreon > 0.5)
{
msg.channel.send('image link');
msg.channel.send('Just bought this with my patreon money.');
}
else
{
msg.channel.send('image link');
msg.channel.send('Just bought 3 of these with my patreon money.')
}
})
这是我在不和谐人的帮助下编写的代码
if(msg.content.toLowerCase() === "yandev, buy something"){
var Patreon = Math.random();
if (Patreon > 0.5)
{
msg.channel.send('image link');
msg.channel.send('Just bought this with my patreon money.');
}
else
{
msg.channel.send('image link');
msg.channel.send('Just bought 3 of these with my patreon money.')
}
else if
{
msg.channel.send('image link')
msg.channel.send('Just bought this with my patreon money.')
}
})
这两个都给出相同的错误:
else if
^^^^
SyntaxError: Unexpected token 'else'
else
^^^^
SyntaxError: Unexpected token 'else'
我尝试自己修复它,但找不到解决方法。 所以现在我在这里。谢谢。
【问题讨论】:
-
else if需要一个条件,else应该在else if之后定义,因为它只会在所有其他条件都失败时运行。 -
"如果 A 为真,做 B,否则做 C,否则如果 D 为真,做 E"。这对你有意义吗?
-
查看MDN Docs 了解
if/else if/else控制语句。
标签: javascript discord.js