我正在嘗試使用 JS 創建一個不和諧的機器人。我為我打算實施的每個命令創建了一個 .js 文件,并且在“主”腳本中有一個檢查將調用其他命令腳本。當我說 VS 代碼不會告訴我參數的變量類型,也不會告訴我有關方法調用的任何信息時,我將使用圖片來說明我的意思。Intellisense 在這些命令 .js 腳本中似乎也不能很好地工作。背景信息:我有更多的 Java 編程經驗。不管出于什么原因,JS 似乎讓我感到困惑,但我想更好地學習和理解它。我不會展示所有代碼,只展示我的示例所需的代碼。main.js 腳本:require('dotenv').config();const { Client } = require('discord.js');const client = new Client();const prefix = "++";const fs = require('fs');client.commands = new Discord.Collection();const commandFiles = fs.readdirSync('.src/commands/').filter(file => file.endsWith('.js'));for(const file of commandFiles){ const command = require(`.src/commands/${file}`); client.commands.set(command.name, command);}client.on('message', (message) => { if(message.author.bot) return; console.log(`[${message.author.tag}]: ${message.content}`); if(!message.content.startsWith(prefix) || message.author.bot) return; const args = message.content.slice(prefix.length).split(/ +/); const command = args.shift().toLowerCase(); if(command === 'ping'){ client.commands.get('ping').execute(message, args);});ping.js 腳本:module.exports = { name: 'ping', description: 'This is a ping command.', execute(message, args){ message.channel.send('Pong!'); }}圖片:它只是說任何,我假設任何變量類型,我認為......但這看起來很混亂并且難以理解。main.js https://gyazo.com/86f7118513df791743def98bcf052f06ping.js https://gyazo.com/06bb2e47a3fd39d2e4445591d8537131
為什么 VS Code 不跟蹤 JavaScript 的變量類型?
呼喚遠方
2023-03-24 16:41:49