javascript - 预期参数表达式和预期声明或语句
问题描述
我在这段代码上有两个错误
第一个错误是最后一个} 中预期的参数表达式。第二个错误是最后一个) 中预期的声明或声明。它可以是未完成的 { 和 ( 但我找不到未完成的。
if (!message.content.startsWith(config.prefix) || message.author.bot) return;
const args = message.content.slice(config.prefix.length).trim().split(/ +/);
const command = args.shift().toLowerCase();
if (command === 'ping') {
message.channel.send('Pong.');
} else if (command === 'help') {
message.channel.send({ embed: {
color: 16758465,
title: "You want help?",
description: ":sparkles:Hi! I'm Ohi bot owned by ilkoshu.",
fields: [{
name: ":fish_cake:Bot Commands",
value: "..commands"
},
{
name: ":strawberry:Contact Me",
value: "..contact"
},
],
timestamp: new Date(),
}
});
}
else if(command === "commands"){
message.channel.send({ embed: {
color: 16758465,
title: "Bot Commands",
fields: [{
name: ":birthday:Fun Commands",
value: "..dice, ..avatar, ..meme, ..say, ..animesuggest, ..top15animech, ..guessage"
},
{
name: ":mushroom:Roleplay Commands",
value: "..hug [user], ..pat [user], ..kiss [user], ..cuddle [user], ..greet [user], ..bite [user], ..slap [user], ..punch [user], ..kill [user], ..run, ..cry, ..smile, ..dance"
},
{
name: ":shaved_ice:Admin Commands",
value: "..ban [user], ..kick [user], ..voicemute [user], ..clear [2-20], ..serverinfo"
},
{
name: ":chocolate_bar:About Bot",
value: "..ping, ..botinfo, ..vote, ..invite"
}],
},
},
//...
});
解决方案
您遇到的错误是由于逗号,
和括号)
放错了位置。首先,你不应该用逗号来关闭函数,除非你在之后调用一个新函数。您没有关闭此行的任何括号message.channel.send({ embed: {
,这导致了 1 个错误。另一个错误是由于以下示例的第一行中存在逗号:
},
//...
});
删除逗号并将括号放在右行后,您的代码最终将如下所示:
if (!message.content.startsWith(config.prefix) || message.author.bot) return;
const args = message.content.slice(config.prefix.length).trim().split(/ +/);
const command = args.shift().toLowerCase();
if (command === 'ping') {
message.channel.send('Pong.');
} else if (command === 'help') {
message.channel.send({ embed: {
color: 16758465,
title: "You want help?",
description: ":sparkles:Hi! I'm Ohi bot owned by ilkoshu.",
fields: [{
name: ":fish_cake:Bot Commands",
value: "..commands"
},
{
name: ":strawberry:Contact Me",
value: "..contact"
},
],
timestamp: new Date(),
}
});
}
else if(command === "commands"){
message.channel.send({ embed: {
color: 16758465,
title: "Bot Commands",
fields: [{
name: ":birthday:Fun Commands",
value: "..dice, ..avatar, ..meme, ..say, ..animesuggest, ..top15animech, ..guessage"
},
{
name: ":mushroom:Roleplay Commands",
value: "..hug [user], ..pat [user], ..kiss [user], ..cuddle [user], ..greet [user], ..bite [user], ..slap [user], ..punch [user], ..kill [user], ..run, ..cry, ..smile, ..dance"
},
{
name: ":shaved_ice:Admin Commands",
value: "..ban [user], ..kick [user], ..voicemute [user], ..clear [2-20], ..serverinfo"
},
{
name: ":chocolate_bar:About Bot",
value: "..ping, ..botinfo, ..vote, ..invite"
}]
}
})
}
我希望它有所帮助,并祝你的编码好运!
推荐阅读
- perl - HTTP::Request 在标头中用连字符替换下划线
- graphql - GitHub GraphQL api 说还有另一个页面,但是使用游标时找不到结果
- r - 比较数据框中的 xy 坐标
- python - 不使用 async-await 的 Python 代码
- javascript - 操作图标未显示 Krajee 文件输入
- ruby-on-rails - 为什么我在 Rails 网站上的链接使用“GET”动词?
- python - 使用 Google Cloud AutoML 模型预测存储在 Firebase 功能中的 Google Cloud 存储中的图像
- functional-programming - 为什么在 ramda.js 中使用“补码”作为函数的名称
- c# - 通用自定义接口 C# 中的逆变不工作
- css - Rails - 如何在每隔一行显示图像及其内容的左右布局