有没有办法让Intellisense在子目录中工作?

huangapple go评论70阅读模式
英文:

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) {
      
   }
};

JSDocs指南
TypeScript指南

英文:

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) {
      
   }
};

有没有办法让Intellisense在子目录中工作?

JSDocs Guide
TypeScript Guide

huangapple
  • 本文由 发表于 2023年6月19日 19:36:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/76506240.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定