最佳答案
我正在尝试制作一个 不和谐机器人,只是说,如果有人在线上的游戏。
然而,我一直收到这样的信息:
[ ERR _ REQUIRE _ ESM ] : 不支持 ES 模块的 request ()。相反,将... 中 index.js 的要求更改为所有 CommonJS 模块中都可用的动态 import ()。
这是我的暗号:
module.exports = {
name: 'username',
description: "this is the username command",
async execute(message, args) {
const fetch = require('node-fetch');
if (args.length !== 1) {
return message.channel.send("invalid username wtf")
}
const ign = args[0]
if (ign.length > 16 || ign.length < 3) {
return message.channel.send("invalid username wtf")
}
const uuid = 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"));
const onlineInfo = await fetch(`https://api.hypixel.net/status?key=${john}&uuid=${uuid}`).then(data => data.json());
if (uuid.length !== 32) {
return;
}
if (onlineinfo.success) {
if (onlineinfo.session.online) {
message.channel.send("they are online")
}
else {
message.channel.send("they are offline")
}
}
else {
message.channel.send("hypixel api bad wtf")
}
}
}
这是我的 包裹 Json文件:
{
"name": "discordbot",
"version": "1.0.0",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node main.js"
},
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"discord.js": "^13.0.1",
"node-fetch": "^3.0.0"
}
}