'Minecraft bot send message if player join in server or leave
I have code if player join or leave = bot print message
const mineflayer = require('mineflayer')
const MinecraftBot = mineflayer.createBot({
host: 'localhost',
username: 'ChatBot',
})
MinecraftBot.on('playerJoined', (player) => {
if (player.username !== MinecraftBot.username) {
MinecraftBot.chat(`Hello ${player.username}`)
}
})
MinecraftBot.on('playerLeft', (player) => {
if (player.username === MinecraftBot.username) return
MinecraftBot.chat(`Bye ${player.username}`)
})
But, if bot join in server and player or players online (if my bot joined earlier if their players), he message. But i need if bot joined and players online, he ignore old players [earlier joined if my bot] (only if NEW player join).
Please help me!
Solution 1:[1]
This will catch players that join 'after' the bot starts. If the bot is running all the time, then it will message everyone eventually. If you restart the bot, or want it to send message to all people online prior to it starting, then you'll need to run through an "init" type function that loops through all members that are online.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | G-Force |
