Skip to content

Storage, timers and HTTP

These are host services. Each needs a capability in the manifest that the owner granted; without it the call fails with NOT_GRANTED.

A private key-value store per bot, kept on the host in its own database (never the community’s) and limited to the granted bytes.

bot.storage.setJSON('counter', 42);
const n = bot.storage.getJSON<number>('counter'); // number | null
const keys = bot.storage.keys('user:', { limit: 100 });
bot.storage.delete('counter');

QUOTA_EXCEEDED means the grant is used up. Data survives restarts and updates, moves with the community’s export, and is deleted when the bot is removed.

const id = bot.timers.after(60_000, 'reminder:42'); // once, in 60 s
const tick = bot.timers.every(3_600_000, 'hourly'); // repeating, at least every second
bot.timers.cancel(id);
bot.on('timer', ({ id, tag }) => bot.log.info('timer', id, tag));

setTimeout and setInterval never fire in a bot: nothing runs between calls. Use these timers.

Timers don’t survive a restart: store what matters and arm timers again when the bot starts (in init/ready in TypeScript, in commands() in Rust).

const res = bot.http.fetch('https://api.open-meteo.com/v1/forecast?latitude=30&longitude=31', { timeoutMs: 5_000 });
const forecast = res.json<{ current?: unknown }>(); // HttpError (kind 'not-granted', …) when refused

There is no global fetch in a bot; this is the only way out.

  • Only https:// URLs, to hosts in both the bot’s grant and the operator’s ceiling.
  • The host resolves the name and refuses loopback, private, link-local and reserved addresses, so a bot can’t reach the host’s own network.
  • Requests leave from the host: the remote server learns the host’s IP address, never a member’s. Owners see the list of hosts on the bot card before granting it.
  • Responses are limited in size (4 MiB) and time.
  • Bots have no sockets: this is the only way out.