javascript - 错误:使用 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 identifier
https://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。
解决方案
推荐阅读
- html - 如何将父 div 的高度设置为具有位置的子 div:绝对
- python - 如何随意停止和启动线程
- javascript - 为什么这不是一个完美的正方形?
- javascript - 我在 ng-repeat 中使用了一个函数,但它的重复次数比数组的总长度多很多倍
- c++ - 覆盖另一个类的朋友的虚拟受保护方法
- c++ - 无法在 IPv4 和 IPv6 中将套接字绑定到端口
- asp.net-mvc - BeginForm 提交时总是调用 Index
- android - 我的工具栏未显示在 CardView 中
- python-requests - 构造一个 POST 请求
- c# - C# - postgresql - 随着时间的推移内存泄漏