我正在尝试使用 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
1 回答

沧海一幻觉
TA贡献1824条经验 获得超5个赞
Discord.jssend()
返回一个Promise<(Message)>
或Promise<(Array<Message>)>
(discord.js 文档中的 channel.send())。Promises 非常适合任何 API 中的顺序任务,但似乎不是您的环境可识别的数据类型。如果 VSCode 和 IntelliJ(以及许多其他 IDE)无法识别您的方法返回值的数据类型,或者如果它没有预定义(因为与 JS 函数或方法相比,它在 Java 中更常见),它们将突出显示该方法的返回值为any
.
添加回答
举报
0/150
提交
取消