我制作了一个discord bot,并在discord服务器上寻求有关此代码的帮助。他们建议在这里询问。
这是的原始代码
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
和else if
。顺序必须始终为if -> else if -> else
。您的else if
中也缺少一个条件。
这是有意义的,因为上一个else
将涵盖所有您没有明确检查的条件。
底部的右括号是什么?根据第一块中提供的代码,它应该是。
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没有条件。
尝试删除第一个块最后一行的"(",看看它是否有效。