首页 > 解决方案 > 预期参数表达式和预期声明或语句

问题描述

我在这段代码上有两个错误

第一个错误是最后一个} 中预期的参数表达式。第二个错误是最后一个) 中预期的声明或声明。它可以是未完成的 { 和 ( 但我找不到未完成的。

    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"
          }],
        },
      },
//...
});

标签: javascriptvisual-studio-codediscorddiscord.js

解决方案


您遇到的错误是由于逗号,和括号)放错了位置。首先,你不应该用逗号来关闭函数,除非你在之后调用一个新函数。您没有关闭此行的任何括号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"
      }]
    }
  })
}

我希望它有所帮助,并祝你的编码好运!


推荐阅读