英文:
Is there a way to get Intellisense to work in subdirectories?
问题
我一直在重新审查我以前使用Discord.JS制作的机器人,有一段时间了,我一直在苦苦挣扎的一件事是,每当在子目录(例如myproject/commands/moderation
)中工作,或者在index.js
之外的任何文件中工作时,我都无法获得discord.js的智能建议,而必须手动输入所有内容。
有没有办法让智能建议在子目录中为我提供建议?或者更有可能的是,我做错了什么?
英文:
I've been revisiting a bot that I've made with Discord.JS a while back, and something I've been struggling with for a while is that whenever working in subdirectories (e.g. myproject/commands/moderation
), or any file outside of index.js
for that matter, I don't get the Intellisense suggestions for discord.js but instead have to type everything manually.
Is there any way to get Intellisense to give me suggestions in subdirectories? Or, more likely, did I do something wrong?
答案1
得分: 2
要么切换到TypeScript并为您的值添加类型注释,要么在定义函数时使用JSDocs。如果您已经在使用TypeScript,那么您需要声明要使用的数据的形状。
TypeScript:
import { SlashCommandBuilder } from "discord.js";
import type { CommandInteraction } from "discord.js";
interface Command {
data: SlashCommandBuilder,
execute: (interaction: CommandInteraction) => void;
};
module.exports = {
data: ...,
execute(interaction) {
}
} 满足 Command;
JSDocs:
// Command file
import { CommandInteraction } from 'discord.js'; // 如果使用ESM
const { CommandInteraction } = require('discord.js'); // 如果使用CommonJS
module.exports = {
data: ...,
/**
*
* @param {CommandInteraction} interaction
*/
execute(interaction) {
}
};
英文:
Either switch over to TypeScript and type annotate your values, or use JSDocs when defining your functions. If you're already using TypeScript, then you need to declare the shape of the data to use.
TypeScript:
import { SlashCommandBuilder } from "discord.js";
import type { CommandInteraction } from "discord.js";
interface Command {
data: SlashCommandBuilder,
execute: (interaction:CommandInteraction) => void;
};
module.exports = {
data: ...,
execute(interaction) {
}
} satisfies Command;
JSDocs:
// Command file
import { CommandInteraction } from 'discord.js'; // If using ESM
const { CommandInteraction } = require('discord.js'); // If using CommonJS
module.exports = {
data: ...,
/**
*
* @param {CommandInteraction} interaction
*/
execute(interaction) {
}
};
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论