Skip to main content
The presence of your bot is what Discord shows under its name in the member list: its status (the colored dot) and what it is doing. It is declared once, with presence(); the templates keep it in src/presence.ts.
src/presence.ts
That is all: as soon as the bot is connected, it is online and “Watching over the server”. Without this file, the bot is online and shows nothing. Both fields are optional: a status alone, or an activity alone, works. Several activities shown in turn, and texts that change, are below.
Everything the file declares is in the reference.

Status

Activity

type says how Discord words it, name is the text after it. A 'streaming' activity needs the url of the stream, and Discord only accepts a Twitch or a YouTube link:
src/presence.ts
A status or a type that is not in these lists, an empty name, or a url on another type, is an error when the file loads, with what to write.

Several activities

activities shows several activities one after the other, each for its for: a duration like '30s' or '2m', 30 seconds when left out, 5 seconds at least. After the last one, the first one comes back.
src/presence.ts
A presence has activity or activities, never both. Which activity is shown is read from the clock: a large bot running on several processes shows the same one everywhere, at the same time.

Texts that change

A name can be a function. It runs each time its activity is shown, and receives guilds, the number of servers the bot is in (all processes together), and t, the texts of your language files in the default language.
src/status.ts
Alone, an activity whose name is a function runs it again every for.

Activities from your data

activities can be a function too, async if it needs to: it gives the list, and runs again each time the list has been shown in full. The activities can then come from a store, kept in a file or in Redis, that a command fills:
src/rotation.ts
When a function throws, or gives something that is not an activity, the error is shown once with the file and the line, and the bot keeps the last text or list that worked. Until a list function has run, the bot shows its status alone. chapterjs test runs each function of the presence once, and reports the one that throws with its line.

In development

In chapterjs dev, saving src/presence.ts changes the presence at once, without reconnecting:
A file that does not load is reported with what is wrong, and the bot keeps the last presence that worked. Deleting the file puts the bot back to online with nothing shown. Discord accepts 5 changes of presence per 20 seconds: when you save faster than that, only the latest one is sent, when it may be. The functions of the presence always run as your files are now, even when the presence file itself did not change. The presence is the bot’s, not the server’s. With one bot for dev and production, what you try here may be shown to everyone: see A second bot for development.

presence() reference

Every field of the presence file.

Tasks

What your bot does by itself, every so often.