A simple bot using mineflayer (javascript) in python
- Install NodeJS
- Install Python >=3.10
pip install uvuv syncuv run -m src.__main__fromsrc.mcbotimportBot, Dispatcherfromsrc.mcbot.typesimportMessagebot=Bot("Botik", "localhost", 3000, "1.20.1", hideErrors=False)
dp=Dispatcher()
@dp.on.spawn()defspawn(*args):
bot.chat("Hello world!")
@dp.on.message()defchat(message: Message) ->None:
if"hi"inmessage.text:
message.bot.chat("Hello!")
if__name__=="__main__":
dp.run(bot)bot_1=Bot("Botik", ...)
bot_2=Bot("Botik_2", ...)
dp=Dispatcher()
# Handlers...if__name__=="__main__":
dp.run(bot_1, bot_2)Tip
1 Tick = 50ms (20 ticks = 1 second)
@dp.on.spawn()defspawn(*args):
bot.chat("Let me jump")
bot.action("jump")
bot.off_action()
@dp.on.message()defchat(message: Message) ->None:
if"jump"inmessage.text:
bot.action("jump")
bot.wait(20)
bot.action("forward")
bot.wait(20)
bot.off_action()@dp.on.entityHurt()defhurt(*args) ->None: # entity, second_entityattacker=bot.nearestEntity()
ifattacker:
bot.attack(attacker)