我正在使用 [this][1] Minecraft 服务器工具,但出现以下错误。无论如何我可以解决这个错误吗?
请注意,该错误不是在运行 bot 时出现的,而是在运行命令 -rcon 时出现的。
这是我的命令处理程序和命令的代码。这是尝试使用 rcon 运行命令“list”。
代码:https://pastebin.com/QWysjvnu
如果有更好的方法可以通过 discord 运行命令,请告诉我。
client.commands.get('rcon').execute(message, args, server);
^
TypeError: Cannot read property 'execute' of undefined
at Client.<anonymous> (/Users/myname/Downloads/Esentrix Bot/main.js:47:36)
at Client.emit (events.js:376:20)
at MessageCreateAction.handle (/Users/myname/Downloads/Esentrix Bot/node_modules/discord.js/src/client/actions/MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (/Users/myname/Downloads/Esentrix Bot/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (/Users/myname/Downloads/Esentrix Bot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:384:31)
at WebSocketShard.onPacket (/Users/myname/Downloads/Esentrix Bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22)
at WebSocketShard.onMessage (/Users/myname/Downloads/Esentrix Bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10)
at WebSocket.onMessage (/Users/myname/Downloads/Esentrix Bot/node_modules/ws/lib/event-target.js:132:16)
at WebSocket.emit (events.js:376:20)
at Receiver.receiverOnMessage (/Users/myname/Downloads/Esentrix Bot/node_modules/ws/lib/websocket.js:835:20)```
------RCON Command-------
module.exports = {
name: 'mcstats',
description: "This command runs commands in Esentrix via rcon!",
execute(message, args){
const util = require('minecraft-server-util');
const client = new util.RCON('esentrixmc.plox.vip', { port: 25575, enableSRV: true, timeout: 5000, password: 'my password here' }); // These are the default options
client.on('output', (message) => {
console.log(message);
// The client must be closed AFTER receiving the message.
// Closing too early will cause the client to never output
// any message.
client.close();
});
client.connect()
.then(() => client.run('list')) // List all players online
.catch((error) => {
console.error(error);
});
}
}
[1]: https://github.com/PassTheMayo/minecraft-server-util
答案 0 :(得分:0)
问题 #1:您将模块嵌套到名为 execute
的父元素中,这样将找不到您的模块。
问题 #2:您的模块的名称是 'mcstats'
,而不是 rcron
。使用正确的名称。
主文件:
client.commands.get('mcstats').execute(message, args, server);
命令文件:
module.exports = {
name: 'mcstats',
description: "This command runs commands in Esentrix via rcon!",
execute(message, args){
const util = require('minecraft-server-util');
const client = new util.RCON('esentrixmc.plox.vip', { port: 25575, enableSRV: true, timeout: 5000, password: 'my password here' }); // These are the default options
client.on('output', (message) => {
console.log(message);
// The client must be closed AFTER receiving the message.
// Closing too early will cause the client to never output
// any message.
client.close();
});
client.connect()
.then(() => client.run('list')) // List all players online
.catch((error) => {
console.error(error);
});
}
}