gpt4 book ai didi

javascript - 错误 [ERR_PACKAGE_PATH_NOT_EXPORTED] : No "exports" main defined in package. json

转载 作者:行者123 更新时间:2023-12-05 01:06:12 30 4
gpt4 key购买 nike

如何解决“错误 [ERR_PACKAGE_PATH_NOT_EXPORTED]:没有在 package.json 中定义的“导出”主程序”?我该如何解决这个错误?我已经尝试了一段时间并得到了帮助,但我们无法弄清楚。我根本不明白这个问题,我越想越困惑。

JavaScript 代码:

const { Client, Intents, Collection } = require('discord.js')
const { REST } = require('@discordjs/rest')
const { Routes } = require('discord-api-types/v9')
const Discord = require('discord.js')

const fs = require('fs')
const intents = new Discord.Intents(32767);
const client = new Discord.Client({ intents });

const config = require('./Data/config.json')

const versionNumber = "V1.0.0"

client.once("ready", () => {
console.log('-------------------------------------------');
console.log(`| Successfully logged in as Logic RP#7590 |`);
console.log('-------------------------------------------');

const commands = []
const commands_information = new Collection();
const commandFiles = fs.readdirSync("./src/commands").filter(file => file.endsWith(".js"))

for (const file of commandFiles) {
const command = require(`./commands/${file}`)
console.log(`Command loaded: ${command.data.name}`)
commands.push(command.data.toJSON())
commands_information.set(command.data.name, command);
}

const rest = new REST({ version: '9' }).setToken(config.token);

(async () => {
try {
console.log('Started refreshing application (/) commands.');
await rest.put(
Routes.applicationGuildCommands(config.clientID, config.guildID),
{ body: commands },
);
console.log('Successfully reloaded application (/) commands.');
} catch (error) {
console.error(error);
}
})();

client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;

const { commandName } = interaction;

if (!commands_information.has(commandName)) return;

try {
await commands_information.get(commandName).execute(client, interaction, config);
} catch (error) {
console.error(error);
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
})
})

client.on("guildMemberAdd", async (member) => {
let members = client.guilds.cache.reduce((a, g) => a + g.memberCount, 0);
console.log(`${member.user.tag} has joined Logic RP`);
console.log('-------------------------------------------');
const embed = new Discord.MessageEmbed()
.setTitle(`Welcome to the ${member.guild.name} Discord server!`)
.setThumbnail(member.user.displayAvatarURL({ dynamic: true }))
.setColor('GREEN')
.addFields(
{
name: "✅ Have fun!",
value: "The most important thing for us is that YOU have fun! You can chat with others in <#898349995315576883> and have all the fun that you want or talk to the community.",
inline: false
},
{
name: "📘 Check out our rules!",
value: "If you'd like to stay in this server, we ask that you read and follow all of our rules in <#898346754926338048>. This is important.",
inline: false
},
{
name: "🔔 Get your roles!",
value: "If you'd like to get notified for certain events or things related to this server, please check out <#898350339571462155> and get the roles that you want.",
inline: false
},
)
.setFooter(`Logic RP | ${versionNumber} - Member #${members}`)
.setTimestamp()

client.channels.cache.get('898346590245363772').send({embeds: [embed]});
})

client.login(config.token);

//npm run dev

JSON 文件:

{
"name": "logic-rp-discord-bot",
"version": "1.0.0",
"description": "Logic RP Discord Bot",
"main": "src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "nodemon -e js"
},
"author": "killrebeest#1001",
"license": "ISC",
"dependencies": {
"@discordjs/builders": "^0.6.0",
"@discordjs/rest": "^0.1.0-canary.0",
"discord-api-types": "^0.23.1",
"discord.js": "^13.3.0-dev.1634342688.38cc89e",
"lodash": "^4.17.21",
"path": "^0.12.7",
"wokcommands": "^1.5.3"
},
"keywords": []
}

Whois.js 代码:

const SlashCommandBuilder = require('@discordjs/builders')
const InteractionResponseType = require('discord-api-types')
const Discord = require('discord.js')

module.exports = {
data: new SlashCommandBuilder()
.setName('whois')
.setDescription(`Information about a specified user.`),
async execute(client, interaction, config) {
const { guild, channel } = interaction

const user = interaction.mentions.users.first() || interaction.member.user
const member = guild.members.cache.get(user.id)

console.log(member)

const embed = new Discord.MessageEmbed()
.setTitle(`Who is ${interaction}?`)
.addFields(
{
name: "User Tag:",
value: user.tag
},
{
name: "Is Bot:",
value: user.bot
},
{
name: "Nickname:",
value: member.nickname || 'None'
},
{
name: "Joined Server:",
value: new Date(member.joinedTimeStamp).toLocaleDateString()
},
{
name: "Joined Discord:",
value: new Date(user.createdTimeStamp).toLocaleDateString()
},
{
name: "Roles",
value: member.roles.cache.size - 1
}
)
.setColor('AQUA')
.setThumbnail(interaction.user.displayAvatarURL({ dynamic: true }))
interaction.reply({ embeds: [embed] })
}}

错误日志:

node:internal/modules/cjs/loader:488
throw e;
^

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in C:\Users\sjim4\Desktop\Logic RP Discord Bot\node_modules\discord-api-types\package.json
at new NodeError (node:internal/errors:371:5)
at throwExportsNotFound (node:internal/modules/esm/resolve:440:9)
at packageExportsResolve (node:internal/modules/esm/resolve:692:3)
at resolveExports (node:internal/modules/cjs/loader:482:36)
at Function.Module._findPath (node:internal/modules/cjs/loader:522:31)
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (C:\Users\sjim4\Desktop\Logic RP Discord Bot\src\commands\whois.js:2:33) {
code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'

任何帮助将不胜感激。

最佳答案

来自 discord-api-types自述文件:

You can only import this module by specifying the API version you want to target. Append /v* to the import path, where the * represents the API version.

因此,您的 require 语句应如下所示:

const { InteractionResponseType } = require('discord-api-types/v9');

关于javascript - 错误 [ERR_PACKAGE_PATH_NOT_EXPORTED] : No "exports" main defined in package. json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69595565/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com