Saltearse al contenido
sern

Presence

Esta página aún no está disponible en tu idioma.

Presence

Your bot should have a personality. (or invite link)

Once

Your presence will be set once, after discord.js Client is called.

./src/presence.js
1
import { Presence } from '@sern/handler'
2
import { ActivityType } from 'discord.js';
3
4
const activity = { type: ActivityType.Listening, name: "what's bofa" };
5
6
export default Presence.module({
7
execute: () => {
8
return Presence
9
.of({ activities: [activity], status: "idle" })
10
.once();
11
}
12
})

Repeated

Set your presence on intervals or events emitted. An example of this is shuffling presences on intervals.

./src/presence.js
1
import { Presence } from '@sern/handler'
2
import { ActivityType, ClientPresenceStatus } from 'discord.js';
3
4
/**
5
* Sorry for using any[]
6
* @param array {any[]}
7
*/
8
function shuffleArray(array) {
9
for (let i = array.length - 1; i > 0; i--) {
10
const j = Math.floor(Math.random() * (i + 1));
11
[array[i], array[j]] = [array[j], array[i]];
12
}
13
return [...array];
14
}
15
16
const statuses = [[ActivityType.Watching, "the sern community", "online"],
17
[ActivityType.Listening, "Evo", "dnd"],
18
[ActivityType.Playing, "with @sern/cli", "idle"],
19
[ActivityType.Watching, "sern bots", "dnd"],
20
[ActivityType.Watching, "github stars go brrr", "online"],
21
[ActivityType.Listening, "what's bofa", "idle"]];
22
23
export default Presence.module({
24
execute: () => {
25
const [type, name, status] = statuses.at(0)!;
26
return Presence
27
//start your presence with this.
28
.of({ activities: [ { type, name } ], status })
29
.repeated(() => {
30
const [type, name, status] = [...shuffleArray(statuses)].shift()!;
31
return {
32
status,
33
activities: [{ type, name }]
34
};
35
}, 60_000); //repeat and setPresence with returned result every minute
36
}
37
})

Inject dependencies

./src/presence.js
1
import { Presence } from '@sern/handler'
2
import { ActivityType } from 'discord.js';
3
4
const activity = { type: ActivityType.Listening, name: "what's bofa" };
5
export default Presence.module({
6
inject: ['@sern/logger'],
7
execute: (logger) => {
8
logger?.info({ message: "Presence changed" });
9
return Presence
10
.of({ activities: [activity], status: "idle" })
11
.once();
12
}
13
})