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));
    
})()

Using the getConsole method

You can also get the current console contents by using the readConsole method. The following code will explain this

This method does not require you to enable the console listening event. You can always use this method.

Last updated

Was this helpful?