【发布时间】:2021-07-15 08:30:45
【问题描述】:
我正在使用 MineFlayer JS 制作一个响应用户消息的基本机器人。这是源代码。我遇到的问题是,当我在聊天中键入 /msg bot test 时,它没有响应我的聊天消息。
// Importing the necessary modules
const mineflayer = require('mineflayer')
// Options for the bot
const options = {
host: 'localhost',
port: 53115,
username: 'bot'
}
// Creating the actual bot
const bot = mineflayer.createBot(options)
// Creating a function to say "Hey I am a bot." in minecraft chat and logs "I spawned." in console
function typeHiInChat() {
bot.chat("Hey! I am a bot.")
console.log('I spawned.')
}
// Creating a function to say "I have been kicked from the server!" open it getting kicked
function onKick() {
console.log('I have been kicked from the server!')
}
// Setting up a listener that listens for the 'spawn' event
bot.once('spawn', typeHiInChat)
// Setting up a listener that listens for the 'kick' event
bot.once('kicked', onKick)
bot.on('message', (message, jsonMSG) => {
msg = JSON.stringify(jsonMSG)
if (msg == "test") {
bot.chat("This Works!")
}
})
当我在 Minecraft 聊天中键入 /msg test 时,它没有响应我的聊天消息。它确实说“嘿!我是机器人。”在聊天中,但不是实际的东西。
【问题讨论】:
标签: javascript mineflayer