我一直在尝试在命令处理程序上实现复杂的代码,但是随后出现错误消息:
TypeError: bal is not a function
at Object.execute (C:\Users\tom\Documents\TJ\bot\commands\uwu uwubon.js:17:7)
at Client.client.on.message (C:\Users\tom\Documents\TJ\bot\index.js:153:11)
at Client.emit (events.js:198:13)
at MessageCreateHandler.handle (C:\Users\tom\Documents\TJ\bot\node_modules\discord.js\src\client\websocket\packets\handlers\MessageCreate.js:9:34)
at WebSocketPacketManager.handle (C:\Users\tom\Documents\TJ\bot\node_modules\discord.js\src\client\websocket\packets\WebSocketPacketManager.js:105:65)
at WebSocketConnection.onPacket (C:\Users\tom\Documents\TJ\bot\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:333:35)
at WebSocketConnection.onMessage (C:\Users\tom\Documents\TJ\bot\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:296:17)
at WebSocket.onMessage (C:\Users\tom\Documents\TJ\bot\node_modules\ws\lib\event-target.js:120:16)
at WebSocket.emit (events.js:198:13)
at Receiver.receiverOnMessage (C:\Users\tom\Documents\TJ\bot\node_modules\ws\lib\websocket.js:789:20)
说实话,我对javascript不太了解,所以我很难单独解决问题。我尝试了各种方法来解决该问题,从在var,let和const之间进行试验,到完全更改代码的组成但无济于事。
如果您想知道我的代码是什么样子,这里是:
const Discord = require('discord.js')
module.exports = {
name: 'uwubon',
colldown: 3,
guildOnly: false,
aliases: [],
rank: 1,
description: '',
execute(message, args) {
var bal = require('../db/uwus.json')
let uwuval = 1000
let menuser = message.guild.member(message.mentions.users.first() || message.guild.member.get(args[0]));
let curuwu = bal[message.guild.member(message.mentions.users.first() || message.guild.member.get(args[0])).uwus]
if (message.author.id == 335562919364263938) {
bal(menuser).uwus = curuwu + uwuval
} else return message.reply('You are not eligible for that command!')
},
};
PS:对于那些想知道的人,是的,我确实重新发布了此信息,因为我不小心使用了其他版本的命令代码。
答案 0 :(得分:0)
bal不是函数,因此您不应使用()
。它是您尝试从json文件提取数据时看到的对象。为了访问对象的数据,您需要将()
替换为[]
。因此,第17行上的bal(menuser)
将是bal[menuser]
。