Client#
- class minecraft.Client#
The Minecraft client.
This abstracts away the connection and provides a simple interface for sending and receiving packets.
- Variables:
- add_handler(packet_type: type[minecraft.packets.base.Packet], handler: Callable[[Packet], Coroutine[None, None, None]]) None#
Add a packet handler.
- handle(packet_type: type[minecraft.packets.base.Packet]) Callable[[Callable[[Packet], Coroutine[None, None, None]]], Callable[[Packet], Coroutine[None, None, None]]]#
A decorator that adds a packet handler.
- async handler_error(handler, error: Exception) None#
Called whenever a packet handler raises an exception.
The default behavior is to print the traceback.
- Parameters:
handler (function) – The handler that raised the exception.
error (Exception) – The exception that was raised.
- async microsoft_auth(client_id: str) None#
Authenticate with Microsoft.
- Parameters:
client_id (str) – The client ID of the application.
- remove_handler(packet_type: type[minecraft.packets.base.Packet], handler: Callable[[Packet], Coroutine[None, None, None]]) None#
Removes a handler for a packet.
- Parameters:
- Raises:
ValueError – The handler is not registered for the packet.
- run(host: str, port: int) None#
Run the bot.
This will block until the connection is closed, and will also handle keyboard interrupts and the event loop for you.
- async send_packet(packet: Packet) None#
Send a packet to the server.
Note
This does not wait for the packet to send. Instead, it adds it to a queue.
- Parameters:
packet (Packet) – The packet to send.
- set_auth_info(username: str, uuid: str, access_token: str) None#
Set the authentication information.
- async setup()#
A utility method that is called before the connection is started.
This takes no parameters and does nothing unless overridden.
- async start(host: str, port: int = 25565) None#
Setup the bot and connect to the server.
This will also wait until the connection is closed before returning.
- async wait_for_packet(packet_type: type[minecraft.packets.base.Packet], *, timeout: float = None) Packet#
Wait for a packet to be received.
- Parameters:
- Returns:
The packet that was received.
- Return type:
- Raises:
asyncio.TimeoutError – The packet was not received before the timeout.