我一直在重温一段时间以前我用Discord.js制作的一个机器人,我一直在努力解决的一件事是,无论何时在子目录(例如myproject/commands/moderation
)或index.js
以外的任何文件中工作,我都没有收到IntelliSense对discord.js的建议,而是不得不手动键入所有内容.
有没有办法让IntelliSense在子目录中给我建议?或者,更有可能的是,我做错了什么?
我一直在重温一段时间以前我用Discord.js制作的一个机器人,我一直在努力解决的一件事是,无论何时在子目录(例如myproject/commands/moderation
)或index.js
以外的任何文件中工作,我都没有收到IntelliSense对discord.js的建议,而是不得不手动键入所有内容.
有没有办法让IntelliSense在子目录中给我建议?或者,更有可能的是,我做错了什么?
或者切换到类型脚本并输入Annotate Your Value,或者在定义函数时使用JSDocs.如果您已经在使用TypeScrip,则需要声明要使用的数据的形状.
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) {
}
};