【问题标题】:Discord.js SyntaxError: Unexpected token '.'Discord.js SyntaxError:意外的标记“。”
【发布时间】:2021-02-09 06:07:51
【问题描述】:

我收到了这个错误

.addField("Among Us related commands",
                 ^

SyntaxError: Unexpected token '.'

当使用帮助命令时,我正在查看有关命令的信息,我试图检查我的代码有什么问题,但没有发现任何问题,请帮助

        const data = [];
        const { commands } = message.client;

        const embed = new Discord.MessageEmbed()
         .setAuthor(`My prefix here is ${prefix}\nuse ${prefix}help <command name> to get info about a command`);
         .addField("Among Us related commands",
         "tips");
         .addField("Among Us Mini Game",
         "soon");
         .addField("Utility commands",
         "ping");
         .setColor('GREEN');
         .setTimestamp();
         .setFooter(message.member.user.tag, message.author.avatarURL());

        const name = args[0]
        const command = commands.get(name) || commands.find(c => c.aliases && c.aliases.includes(name))

        if(!args.length) {
            return message.channel.send(embed)
        }

        const helpembed = new Discord.MessageEmbed()
         .setTitle(`${command.name} command`)
         .addField("Description", command.desciption)
         .addField("Aliases", command.aliases || "none")
         .addField("Usage", command.usage || "none")
         .addFIeld("Example", command.example || "none")
         .setTimestamp()
         .setFooter(message.member.user.tag, member.author.avatarURL())

        message.channel.send(helpembed)


【问题讨论】:

    标签: node.js discord.js


    【解决方案1】:

    使用function chaining,需要去掉函数之间的分号:

    const embed = new Discord.MessageEmbed()
      // ...
      .setTimestamp(); // ; needs to be removed
      .setFooter(message.member.user.tag, message.author.avatarURL());
    

    最终结果:

    const embed = new Discord.MessageEmbed()
      .setAuthor(`My prefix here is ${prefix}\nuse ${prefix}help <command name> to get info about a command`)
      .addField("Among Us related commands", "tips")
      .addField("Among Us Mini Game", "soon")
      .addField("Utility commands", "ping")
      .setColor('GREEN')
      .setTimestamp()
      .setFooter(message.member.user.tag, message.author.avatarURL());
    

    【讨论】:

      猜你喜欢
      • 2020-09-28
      • 2018-08-02
      • 2020-10-03
      • 2022-01-26
      • 2022-12-13
      • 2020-11-10
      • 1970-01-01
      • 2016-04-21
      • 2020-12-03
      相关资源
      最近更新 更多