Chatting is a core part of any bot, allowing the bot to talk to players and the players to talk to the bot.
To get chat messages, you can use the chat hook provided by yolkbot. This hook will trigger whenever a new chat message is received.
bot.on('chat', (player, message, flags) => {
console.log(`Received chat message: ${message}`);
});
The player is an object representing the player who sent the message. WARNING: THIS CAN SOMETIMES BE UNDEFINED! If something like a mod sends one of the green MOD messages, the player will be undefined. This is because the message is not sent by a player, but rather by the game itself. If the player is undefined, flags will either be:
SEVER message (likely sent by Harrison/a game dev)MOD message (sent by a mod)If you just want to ignore these (recommended), you can do the following:
bot.on('chat', (player, message, flags) => {
if (!player) return;
console.log(`Received chat message from ${player.name}: ${message}`);
});
Or, if you want to only listen to MOD or SERVER messages, you can do the following:
bot.on('chat', (player, message, flags) => {
if (flags === 254) {
console.log(`Received MOD message: ${message}`);
} else if (flags === 255) {
console.log(`Received SERVER message: ${message}`);
}
});
Otherwise, player will be the player's object from bot.players, and you can do normal things like player.name or player.id to get information about the player.
To send chat messages, you can use the ChatDispatch dispatch. This allows you to send a chat message to the game.
import ChatDispatch from 'yolkbot/dispatches/ChatDispatch';
bot.dispatch(new ChatDispatch('Hello, world!'));
You can read more about the ChatDispatch in the ChatDispatch documentation.
The game has weird chat limitations. In order to chat, one of the following must be true:
bot.game.isPrivate)bot.account.emailVerified)bot.account.isAged)If none of these are true, the bot will not be able to chat. This is a limitation of the game itself, and there is no way to bypass it.
Furthermore, in PUBLIC GAMES ONLY, there is a ratelimit based on a variable named chatLines. Here's how it works:
This means that the ratelimit will increase over time and become more strict the more you send messages. You will be able to send messages without limits roughly every 4 seconds (3960ms to be exact), but this is not guaranteed.
Chatting is a core part of any bot, allowing the bot to talk to players and the players to talk to the bot.
To get chat messages, you can use the chat hook provided by yolkbot. This hook will trigger whenever a new chat message is received.
bot.on('chat', (player, message, flags) => {
console.log(`Received chat message: ${message}`);
});
The player is an object representing the player who sent the message. WARNING: THIS CAN SOMETIMES BE UNDEFINED! If something like a mod sends one of the green MOD messages, the player will be undefined. This is because the message is not sent by a player, but rather by the game itself. If the player is undefined, flags will either be:
SEVER message (likely sent by Harrison/a game dev)MOD message (sent by a mod)If you just want to ignore these (recommended), you can do the following:
bot.on('chat', (player, message, flags) => {
if (!player) return;
console.log(`Received chat message from ${player.name}: ${message}`);
});
Or, if you want to only listen to MOD or SERVER messages, you can do the following:
bot.on('chat', (player, message, flags) => {
if (flags === 254) {
console.log(`Received MOD message: ${message}`);
} else if (flags === 255) {
console.log(`Received SERVER message: ${message}`);
}
});
Otherwise, player will be the player's object from bot.players, and you can do normal things like player.name or player.id to get information about the player.
To send chat messages, you can use the ChatDispatch dispatch. This allows you to send a chat message to the game.
import ChatDispatch from 'yolkbot/dispatches/ChatDispatch';
bot.dispatch(new ChatDispatch('Hello, world!'));
You can read more about the ChatDispatch in the ChatDispatch documentation.
The game has weird chat limitations. In order to chat, one of the following must be true:
bot.game.isPrivate)bot.account.emailVerified)bot.account.isAged)If none of these are true, the bot will not be able to chat. This is a limitation of the game itself, and there is no way to bypass it.
Furthermore, in PUBLIC GAMES ONLY, there is a ratelimit based on a variable named chatLines. Here's how it works:
This means that the ratelimit will increase over time and become more strict the more you send messages. You will be able to send messages without limits roughly every 4 seconds (3960ms to be exact), but this is not guaranteed.