💡 🔊 🎨 ♻️ updatePresence Handler

This commit is contained in:
Axel Olausson Holtenäs 2022-10-24 01:05:04 +02:00
parent 092b4be7b4
commit c352a08295
No known key found for this signature in database
GPG key ID: BEDBB4D61E6C8462

View file

@ -4,17 +4,26 @@ import logger from "../../middlewares/logger";
// Function
export default (client: Client) => {
if (!client?.user) throw new Error("Client's user is undefined.");
const { guilds } = client;
// 1. Destructure the client.
const { guilds, user } = client;
if (!user) throw new Error("No user found");
// 2. Get the total number of guilds and members.
const memberCount = guilds.cache.reduce((a, g) => a + g.memberCount, 0);
const guildCount = guilds.cache.size;
const status = `${memberCount} users in ${guildCount} guilds.`;
client.user.setPresence({
activities: [{ type: ActivityType.Watching, name: status }],
status: "online",
// 3. Set the presence.
user.setPresence({
activities: [
{
name: `${guildCount} guilds | ${memberCount} members`,
type: ActivityType.Watching,
},
],
});
logger.info(`Client's presence is set to "${status}"`);
// 4. Log the presence.
return logger.info(
`👀 Presence set to "${guildCount} guilds | ${memberCount} members"`
);
};