javascript - SyntaxError:意外的令牌“导出”
问题描述
所以是的,我会直截了当,一个错误被抛出,而我不知道该怎么做,这很奇怪,因为代码很好,只是我在这里说的有问题。这是问题所在:
const { codeBlock } = require("@discordjs/builders");
const { ExplicitContentFilterLevels } = require("discord.js/typings/enums.d.ts");
async function clean(client, text) {
if (text && text.container.name == "Promise")
text = await text;
if (typeof text !== "string")
text = require("util").inspect(text, {depth: 1});
text = text
.replace(/`/g, "`" + String.fromCharCode(8023))
.replace(/@/g, "@" + String.fromCharCode(8023));
text = text.replaceAll(client.token, "[REDACTED]");
return text;
}
exports.run = async (client, message, args, level) => {
const code = args.join(" ");
const evaled = eval(code);
const cleaned = await clean(client, evaled);
message.channel.send(codeBlock("js", cleaned));
};
exports.conf = {
enabled: true,
guildOnly: false,
aliases: [],
permLevel: "Bot Owner"
};
exports.help = {
name: "eval",
category: "System",
description: "Evaluates arbitrary javascript.",
usage: "eval [...code]"
};
这是向我抛出错误的地方:
ERROR Unhandled rejection: SyntaxError: Unexpected token 'export'
C:\Users\emilb\OneDrive\Desktop\Tap\node_modules\discord.js\typings\enums.d.ts:4
export const enum ActivityTypes {
^^^^^^
SyntaxError: Unexpected token 'export'
at Object.compileFunction (node:vm:352:18)
at wrapSafe (node:internal/modules/cjs/loader:1031:15)
at Module._compile (node:internal/modules/cjs/loader:1065:27)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:94:18)
at Object.<anonymous> (C:\Users\emilb\OneDrive\Desktop\Tap\commands\eval.js:2:41)
解决方案
您不应该导入*.d.ts
文件。这些文件是 TypeScript 定义文件,可以帮助您 IDE 提供更好的类型提示。
将导入更改为:
const { ExplicitContentFilterLevels } = require("discord.js/src/util/Constants");
或者甚至更好地将其更改为下面的行,因为这样您就不会被 Discord 包的内部结构所束缚。
const { Constants: { ExplicitContentFilterLevels } } = require('discord.js');
推荐阅读
- html - 文本背景不受文本大小和居中影响
- javascript - 我的 w3 Accordion 菜单没有在 google chrome 中展开?
- android - 同时访问相机
- java - MyBatis sqlMapGenerator 自动生成的问题
- javascript - 如何在将 html5 视频上传到服务器之前对其进行剪切
- regex - 在 tex 的不同行上匹配多个正则表达式组以打印到 csv
- python - 使用 selenium 解决导入问题
- pandas - 熊猫数据框列 - 如何根据多个条件选择列的子集
- flutter - Flutter PageView - 动画颜色所以当前项目是彩色的,其余的是黑色和白色
- html - 将简单 XML 输出为 HTML 表的 XSLT?