Skip to content

Fsoky/mcbot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Minecraft bot

A simple bot using mineflayer (javascript) in python

Setup

  • Install NodeJS
  • Install Python >=3.10

Install UV for venv

pip install uv

Sync dependencies

uv sync

Run the file

uv run -m src.__main__

Examples

Basic example

from src.mcbot import Bot, Dispatcher
from src.mcbot.types import Message

bot = Bot("Botik", "localhost", 3000, "1.20.1", hideErrors=False)
dp = Dispatcher()


@dp.on.spawn()
def spawn(*args):
    bot.chat("Hello world!")


@dp.on.message()
def chat(message: Message) -> None:
    if "hi" in message.text:
        message.bot.chat("Hello!")


if __name__ == "__main__":
    dp.run(bot)

Multiple bot example

bot_1 = Bot("Botik", ...)
bot_2 = Bot("Botik_2", ...)
dp = Dispatcher()

# Handlers...

if __name__ == "__main__":
    dp.run(bot_1, bot_2)

Actions example

Tip

1 Tick = 50ms (20 ticks = 1 second)

@dp.on.spawn()
def spawn(*args):
    bot.chat("Let me jump")
    bot.action("jump")
    bot.off_action()


@dp.on.message()
def chat(message: Message) -> None:
    if "jump" in message.text:
        bot.action("jump")
        bot.wait(20)
        bot.action("forward")
        bot.wait(20)
        bot.off_action()

Attack the entity when the bot is hurt

@dp.on.entityHurt()
def hurt(*args) -> None: # entity, second_entity
    attacker = bot.nearestEntity()
    if attacker:
        bot.attack(attacker)

About

Bot for minecraft

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages