【发布时间】:2021-11-03 22:46:39
【问题描述】:
我正在尝试制作一个不和谐的机器人,它只会显示是否有人在游戏中在线。
但我不断收到此消息:
[ERR_REQUIRE_ESM]:不支持 ES 模块的 require()。而是将 index.js in... 的 require 更改为在所有 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")
}
}
}
这是我的 package.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"
}
}
【问题讨论】:
-
我没有所有 module.exports 的东西,我需要吗?我只是说出口类什么的,有错吗?
标签: javascript node.js discord.js node-fetch hypixel-api