New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

bonkbot

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bonkbot

A bonk.io botting library

latest
Source
npmnpm
Version
4.0.4
Version published
Maintainers
1
Created
Source

BonkBot.js

BonkBot is a JavaScript library for creating bots for the web game Bonk.io. It provides an easy way to create custom bots that can automate various actions within the game. With BonkBot, you can interact with the game's websocket protocol easily, chat with other players, and perform actions such as joining and leaving rooms.

V4 Alpha, report any issues/bugs in the issues tab

Newer NodeJS versions may encounter issues, node 18 and 16 are confirmed working

Installation

To install BonkBot, you will need Node.js installed on your system. Then, run the following command in your terminal:

npm install bonkbot

Features

  • Connect to existing rooms or create new ones
  • Automatically determine the optimal server using the game's API
  • Send and receive chat messages
  • Track players joining and leaving
  • Manage teams and game settings
  • Handle game events
  • Comprehensive error handling
  • Detailed logging

Support

Discord Server

Basic Usage

const { createBot, LOG_LEVELS } = require('bonkbot');

// Create a bot instance
const bot = createBot({
	account: {
		username: 'BotName',
		guest: true, // Use guest account
	},
	logLevel: LOG_LEVELS.WARN, // Set log level (DEBUG, INFO, WARN, ERROR, NONE)
});

// Initialize and handle events
bot.events.on('ready', async () => {
	await bot.connect();
});

// Handle chat messages
bot.events.on('CHAT_MESSAGE', (message) => {
	console.log(`${message.player.username}: ${message.message}`);

	// Respond to !ping command
	if (message.message === '!ping') {
		bot.chat('Pong!');
	}
});

bot.events.on('PACKET', (packet) => {
	bot.autoHandlePacket(packet);
});

bot.init();

Authentication Examples

Automatic Server Detection

By default, BonkBot will automatically determine the optimal server to connect to by querying the game's API. This ensures your bot connects to the most appropriate server based on the current game infrastructure.

If you want to override this behavior and connect to a specific server, you can provide the server option when creating the bot:

const bot = createBot({
	// ... other options
	server: 'b2ny1', // Force connection to a specific server
});

Guest Account

const bot = createBot({
	account: {
		username: 'BotName',
		guest: true,
	},
	logLevel: LOG_LEVELS.WARN,
});

User Account

const bot = createBot({
	account: {
		username: 'YourUsername',
		password: 'YourPassword',
		guest: false,
	},
	logLevel: LOG_LEVELS.WARN,
});

Connection Flow and Examples

The connection flow typically follows this sequence:

  • Bot initialization (bot.init())
  • Ready event fires when login completes
  • Connect to game server (bot.connect())
  • Find or create room
  • Join room or create room
  • Handle game events

Joining a Room by Name

bot.events.on('ready', async () => {
	try {
		// Find room by name
		const roomInfo = await bot.getAddressFromRoomName('roomName');
		console.log(`Found room: ${roomInfo.roomname}`);

		// Set address and connect
		bot.setAddress(roomInfo);
		await bot.connect();

		// Join with optional password
		await bot.joinRoom({
			password: 'optional-password',
		});
	} catch (error) {
		console.error('Failed to join room:', error);
	}
});
bot.events.on('ready', async () => {
	try {
		// Get room info from share link
		const roomInfo = await bot.getAddressFromUrl('https://bonk.io/123abc');
		console.log(`Found room: ${roomInfo.roomname}`);

		// Connect to room
		bot.setAddress(roomInfo);
		await bot.connect();
		await bot.joinRoom();
	} catch (error) {
		console.error('Failed to join room:', error);
	}
});

Creating a Room

bot.events.on('ready', async () => {
	try {
		// Connect to server first
		await bot.connect();

		// Then create room
		bot.createRoom({
			roomname: 'BonkBot Room',
			maxplayers: 10,
			roompassword: '',
			hidden: true,
		});
	} catch (error) {
		console.error('Failed to create room:', error);
	}
});

// Get share link when room is created
bot.events.on('ROOM_SHARE_LINK', (data) => {
	console.log(`Room created! URL: ${data.url}`);
});

Available Events

EventDescriptionReturns
readyBot is ready to connect-
connectConnected to server-
PACKETAny packet received{type, ...data}
JOINJoined a room{game, room, players}
PLAYER_JOINPlayer joined room{player, id}
PLAYER_LEAVEPlayer left room{player, id}
CHAT_MESSAGEChat message received{player, message}
TEAM_CHANGEPlayer changed team{player, team}
HOST_TRANSFERHost was transferred{oldHost, newHost}
READY_CHANGEPlayer ready status changed{player, ready}
GAME_STARTGame started-
GAME_ENDGame ended-
COUNTDOWNGame countdown{countdown}
MAP_SWITCHMap was switched{map}
MAP_SUGGESTMap was suggested{title, author, player}
CHANGE_ROUNDSRound count changed{rounds}
GAMEMODE_CHANGEGame mode changed{mode, engine}
ROOM_SHARE_LINKRoom link created{url}
PLAYER_KICKPlayer was kickedplayer
PLAYER_TABBEDPlayer tabbed in/out{player, tabbed}
PLAYER_INPUTPlayer input received{player, movement}
TEAMLOCK_TOGGLETeams locked/unlocked{teamsLocked}
ROOM_NAME_UPDATERoom name changed{name}
ROOM_ADDRESSRoom address updated{address}
BALANCE_SETPlayer balance changed{player, balance}
disconnectDisconnected from server-

Common Methods

// Chat message
bot.chat('Hello world');

// Get all players
const players = bot.getAllPlayers();

// Get host
const host = bot.getHost();

// Get room share link
const shareLink = bot.getShareLink();

// Set player ready status
bot.ready(true);

// Join a team (0-5)
bot.joinTeam(2); // 0=spectator, 1=FFA, 2=red, 3=blue...

// Give host to player
bot.giveHost(playerId);

// Kick a player
bot.kickPlayer(playerId);

// Leave the room
bot.leaveGame();

Examples

Check out the examples directory for more examples:

  • simple-bot.js: A basic bot that connects to a room and responds to chat commands
  • host-bot.js: A bot that creates and hosts a room

Contributing

Contributions are always welcome! If you find a bug or have a feature request, please open an issue on the project's GitHub page.

License

BonkBot is open-source software licensed under the GPL-3.0 License.

Keywords

bonk.io

FAQs

Package last updated on 05 Nov 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts