我正在嘗試使用 JS 創(chuàng)建一個(gè)不和諧的機(jī)器人。我為我打算實(shí)施的每個(gè)命令創(chuàng)建了一個(gè) .js 文件,并且在“主”腳本中有一個(gè)檢查將調(diào)用其他命令腳本。當(dāng)我說 VS 代碼不會(huì)告訴我參數(shù)的變量類型,也不會(huì)告訴我有關(guān)方法調(diào)用的任何信息時(shí),我將使用圖片來說明我的意思。Intellisense 在這些命令 .js 腳本中似乎也不能很好地工作。背景信息:我有更多的 Java 編程經(jīng)驗(yàn)。不管出于什么原因,JS 似乎讓我感到困惑,但我想更好地學(xué)習(xí)和理解它。我不會(huì)展示所有代碼,只展示我的示例所需的代碼。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!'); }}圖片:它只是說任何,我假設(shè)任何變量類型,我認(rèn)為......但這看起來很混亂并且難以理解。main.js https://gyazo.com/86f7118513df791743def98bcf052f06ping.js https://gyazo.com/06bb2e47a3fd39d2e4445591d8537131
為什么 VS Code 不跟蹤 JavaScript 的變量類型?
呼喚遠(yuǎn)方
2023-03-24 16:41:49