问题描述
我正在尝试制作一个不和谐的机器人,它只会显示是否有人在游戏中在线.
I'm trying to make a discord bot that just vpn下载 says if someone is 免费vpn online on free vpn下载 vpn the game.
但我不断收到此消息:
[ERR_REQUIRE_ESM]:不支持 ES 模块的 require().而是将 index.js in... 的 require 更改为在所有 免费vpn CommonJS 模块中都可用的动态 vpn下载 import().
[ERR_REQUIRE_ESM]: require() of ES Module vpn free from not supported. Instead change the require of index.js in... to a dynamic vpn下载 import() which vpn下载 is available in all CommonJS modules.
这是我的代码:
module.exports = {
name: 'username',
vpn free description: "this is 免费vpn下载 the username command",
vpn free 免费vpn async execute(message, args) {
免费vpn 免费vpn下载
const fetch = 免费vpn下载 require('node-fetch');
vpn下载
vpn free if (args.length !== 1) {
return message.channel.send("invalid username wtf")
free vpn 免费vpn }
免费vpn
const ign = args[0]
if (ign.length > 16 || ign.length < 3) {
free vpn 免费vpn下载 return message.channel.send("invalid username wtf")
}
免费vpn下载
免费vpn 免费vpn下载 const uuid 免费vpn下载 = await fetch(`https://api.mojang.com/users/profiles/minecraft/${ign}`).then(data => data.json()).then(data => data.id).catch(err => message.channel.send("error wtf"));
免费vpn const onlineInfo = await fetch(`https://api.hypixel.net/status?key=${john}&uuid=${uuid}`).then(data => data.json());
vpn free vpn free
if (uuid.length !== 32) {
return;
}
免费vpn
if (onlineinfo.success) {
免费vpn vpn free 免费vpn free vpn if (onlineinfo.session.online) vpn下载 {
vpn free message.channel.send("they are free vpn online")
}
else {
message.channel.send("they are offline")
vpn下载 免费vpn free vpn }
}
else vpn free {
免费vpn下载 vpn下载 vpn下载 vpn下载 message.channel.send("hypixel api bad wtf")
}
}
}
这是我的 package.json:
This is my package.json:
{
"name": "discordbot",
"version": "1.0.0",
"main": "main.js",
"scripts": {
"test": "echo 免费vpn "Error: no test specified" && exit 1",
vpn下载 免费vpn下载 "start": "node main.js"
vpn下载 vpn free },
免费vpn vpn free "author": "",
"license": "ISC",
"description": "",
vpn free vpn free "dependencies": {
vpn free 免费vpn "discord.js": "^13.0.1",
vpn free "node-fetch": "^3.0.0"
}
}
推荐答案
node-fetch v3 最近停止了对 require 导入方式的支持,转而支持 ES 模块.您现在需要使用 ESM 导入,例如:
node-fetch v3 recently stopped 免费vpn support for the require way of importing it in favor of ES Modules. You'll need to use ESM imports now, like:
import fetch from "node-fetch";
在文件的顶部.
这篇关于错误 vpn下载 [ERR_REQUIRE_ESM]:不支持 ES 模块的 require()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!



大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账免费vpn织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)