【问题标题】:Argument expression expected and Declaration or statement expected预期参数表达式和预期声明或语句
【发布时间】:2021-09-12 01:12:32
【问题描述】:

这段代码有两个错误

第一个错误是 需要参数表达式 in last }。 第二个错误是 Declaration or statement expected 在最后)。 它可以是未完成的 { 和 ( 但我找不到未完成的。

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

【问题讨论】:

    标签: javascript visual-studio-code discord discord.js


    【解决方案1】:

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

    希望对您有所帮助,祝您编码顺利!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-08-20
      • 2017-01-26
      • 2021-12-13
      • 2021-02-09
      • 2018-06-12
      • 2015-12-29
      相关资源
      最近更新 更多