Reading from console
There are 2 ways to read from the CubedCraft console. Both will be explained
Using the console event
You can use the event from the session that fires when new console content is present. The code is pretty straight foward
// Dependencies
const { Session } = require('cubed-session');
(async () => {
// Starting a new session
const session = new Session({ listenConsole: true });
// Logging in
await session.login('username', 'password');
// Getting a list of all servers and finding the one we need
const servers = await session.getServers();
const server = servers.find(s => s.name.toLowerCase() === "Server_Name".toLowerCase());
// Selecting the server
await session.selectServer(server.code);
// Listening for the event
session.on('console', (text) => console.log(text));
})()By default the session will not listen for console updates. You will have to enable it by passing in an object with settings when you create a session. The setting listenConsole will decide if your session will listen for console content. So make sure to enable it when attempting to use this event
Using the getConsole method
When using this method, make sure to not request it a lot in a short period of time. Since you are essentially requesting the website over and over again. Try to limit your requests to about 1 every 3 seconds.
You can also get the current console contents by using the readConsole method. The following code will explain this
Last updated
Was this helpful?