首页 > 解决方案 > 错误:使用 eval 命令时出现意外的标识符

问题描述

好的,所以我关注了一个关于如何制作 Eval 命令的 youtube 视频(源代码:https ://github.com/MenuDocs/Discord.JS-Tutorial/blob/Episode-21/commands/owner/eval.js )和在他们的视频中,他们可以做到eval message.author.id并且成功了。而在我的机器人中,它在聊天中出现错误:(Error while evaluating: Unexpected identifierhttps://imgur.com/a/1NWuWEy *注意我使用 2 'a's 将其与我的在线机器人分开,减少重复消息)。

case 'evaal':
                const args = message.content.substring(PREFIX.length).trim().split(" ");
                const ownerID = '285198963722944514';
                if(message.author.id == ownerID) {
                    try {
                        let toEval = args.join(" ")
                        let evaluated = inspect(eval(toEval, { depth: 0 }));

                        if (!toEval) {
                            return message.channel.send("Error while evaluating: \`cannot evaluate air\`!");
                        } else {
                            let hrStart = process.hrtime()
                            let hrDiff;
                            hrDiff = process.hrtime(hrStart);
                            return message.channel.send(`*Executed in ${hrDiff[0] > 0 ? `${hrDiff[0]}s ` : ''}${hrDiff[1] / 1000000}ms.*\n\`\`\`javascript\n${evaluated}\n\`\`\``, { maxLength: 1900 })
                        }

                    } catch (e) {
                        return message.channel.send(`Error while evaluating: \`${e.message}\``)
                    }

                  } else {
                    return message.reply('You are not allowed to use this command. (Owner Only)').then(m => m.delete(5000))
                  }
        break;

如上面 imgur 图像中的链接,机器人会响应但仅显示错误消息。我希望它告诉我消息的作者(我)的 id。

标签: javascriptdiscorddiscord.js

解决方案


推荐阅读