Guides
Start a bot and wait for it
Bot commands only work while the bot is online. Logging in takes anywhere from a few seconds to a minute, so Login Bot answers straight away with status: "connecting" and you check back until it's online.
Code
// Needs the bots:lifecycle scope
async function startBot(botId) {
const headers = { Authorization: `Bearer ${accessToken}` }
const res = await fetch(`https://api.lifebots.cloud/api/v1/bots/${botId}/login`, {
method: 'POST',
headers
})
const json = await res.json()
if (!json.success) throw new Error(json.error.message) // e.g. PASSWORD_REQUIRED
if (json.data.status === 'online') return // already running
// Logging in takes a while - poll every 5 seconds, for up to 2 minutes
for (let i = 0; i < 24; i++) {
await new Promise((r) => setTimeout(r, 5000))
const bot = await fetch(`https://api.lifebots.cloud/api/v1/bots/${botId}`, { headers })
.then((r) => r.json())
if (bot.data.status === 'online') return
if (bot.data.status === 'error') throw new Error(bot.data.botError)
}
throw new Error('Bot did not come online in time')
}What can go wrong
| You get | Why | What to do |
|---|---|---|
PASSWORD_REQUIRED | LifeBots has no Second Life password for the bot. | Ask the user to set it on lifebots.cloud. |
BOT_EXPIRED | The bot's subscription ran out. | Ask the user to renew it. |
status error | Second Life refused the login. | Show botError to the user. |