1.1.2 ā€¢ Published 10 months ago

discord.js-presence v1.1.2

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

šŸ“… Update scheduled!

An update is scheduled sometime to support activities and statuses in cycles. This might be major, but I don't know yet.

šŸ” Are you confused or too lazy to make a cycling presence in discord.js? Me too!

Welcome to the discord.js-presence package, a lightweight toolset for easily creating statuses, cycling statuses, and others in discord.js. Disclaimer that I do not own discord.js as a whole. This uses a modular format similar to discord.js.

I created this tool for my own project and wanted to share it with other people who might want it for creating statuses and managing presences, easily.

I think you can both use import and require for this package, but I'm more of a require guy.

šŸ¤” So... how do you use it?

You use the discord.js-presence package by using functions in the package, which you can use in .js files, like this.

const PresenceManager = require('discord.js-presence');
const PresenceToolkit = new PresenceManager();

client.once(Events.ClientReady, newClient => {
    PresenceToolkit.setStatus(newClient, 'online');
});

Before starting, to make the invisible and dnd presences more compatible, you will need to add GatewayIntentBits.GuildPresences to your intents.

Pretty simple, right? We'll go over what each function and variable does next. Disclaimer that all functions are marked as async. There are a whopping 12 functions for purely presences in this package, so look around for them!

Variables

Functions

  • setStatus

Rundown

Arguments: client*, status*

The setStatus() function sets the status of the bot only limited to these options: idle, dnd, online, invisible.

āš ļø Your bot may become rate limited if you change the status too fast.

Example

PresenceToolkit.setStatus(newClient, 'dnd')

output.png

  • setActivity

Rundown

Arguments: client*, description*, type*

The setActivity() function statically sets the activity of the bot. The argument description sets the activity text to what you want it to be. type accepts any Enum of ActivityType, the most common being ActivityType.Playing.

āš ļø It can be considered dangerous if the activity is changing less than a span of 10/20 seconds.

Example

PresenceToolkit.setActivity(client, 'over every person', ActivityType.Watching)

output.png

  • registerActivities

Rundown

Arguments: client*, activities*

The registerActivity() function 'registers' an activity to a cycle. It accepts an array of activities to cycle through in one go. It will eventually support both statuses and activities.

āš” Getting deprecated from registerActivities to registerProfiles later.

Example

PresenceToolkit.registerActivities(newClient, [
	{ description: 'discord.js', type: ActivityType.Playing }, // Playing **discord.js**
	{ description: 'music', type: ActivityType.Listening }, // Listening to **music**
	{ description: 'a game', type: ActivityType.Competing }, // Competing in **a game**
]);
  • setPlaceholderActivity

Rundown

Arguments: description*, type*

The setPlaceholderActivity() function overrides the default placeholder status if cycling statuses are stopped. (Or no status is specified?)

Example

PresenceToolkit.setPlaceholderActivity(newClient, 'nothing, really', ActivityType.Playing);

gifdemo.gif

  • unregisterActivities

Rundown

Arguments: client*, activities*

The unregisterActivities() function 'unregisters' an activity from the registerActivities() function. You can specify the number index starting from index 0, or find an activity with a description by turning it into a string. Either way, it unregisters the activity if it was found.

āš” Getting deprecated from unregisterActivities to unregisterProfiles later.

Example

āœ… PresenceToolkit.unregisterActivities(newClient, [0, 1, 2]);
āœ… PresenceToolkit.unregisterActivities(newClient, ['Some activity to find', 'Some other activity to find']);
ā›” PresenceToolkit.unregisterActivities(newClient, ['Some activity to find', 0, 1, 'This will not work']);
  • changeCyclingSpeed

Rundown

Arguments: client*, speed*

The changeCyclingSpeed() function changes the cycling speed. There are ratelimits.

Example

ā›” PresenceToolkit.changeCyclingSpeed(newClient, 5);
āœ…āš ļø PresenceToolkit.changeCyclingSpeed(newClient, 7);
āœ… PresenceToolkit.changeCyclingSpeed(newClient, 10);
  • startCycling

Rundown

Arguments: client*

The startCycling() function starts cycling through registered activities/presences.

Example

PresenceToolkit.registerActivities(newClient, [
	{ description: '1', type: ActivityType.Watching },
	{ description: '2', type: ActivityType.Listening },
	{ description: '3', type: ActivityType.Competing },
	{ description: '4', type: ActivityType.Playing },
]);

PresenceToolkit.startCycling(newClient);

result.gif

  • stopCycling

Rundown

Arguments: client*

The stopCycling() function is almost identical to the startCycling() function, but it kills the cycle immediately instead, and it doesn't check whether it's going or not.

Example

PresenceToolkit.stopCycling(newClient);
  • restartCyclingLoop

Rundown

Arguments: client*

The restartCyclingLoop() function is not needed and not a main part, but it forcefully immediately restarts the cycle in case you need it.

Example

PresenceToolkit.restartCyclingLoop(newClient);
  • cycleActivity

Rundown

Arguments: client*

The cycleActivity() function is generally only needed in the main script, not anywhere else. Mostly useless, just controls the cycle.

Example

PresenceToolkit.cycleActivity(newClient);
  • setPlaceholderEnabled

Rundown

Arguments: client*, bool*

The setPlaceholderEnabled() function controls on whether the placeholder status is enabled or not.

Example

PresenceToolkit.setPlaceholderEnabled(newClient, true);
PresenceToolkit.setPlaceholderEnabled(newClient, false);
  • clearActivity

Rundown

Arguments: client*

The clearActivity() function immediately clears the activity, but does not ignore the cycle.

Example

PresenceToolkit.setActivity(client, 'a secret', ActivityType.Watching)
PresenceToolkit.clearActivity(newClient);

šŸ‘‹ Thanks for reading!

Thank you for reading (or scrolling to the end brainlessly) and goodbye! I hope you enjoy this package and find out lots of cool stuff here, as well as at discord.js!

1.1.2

10 months ago

1.0.6

10 months ago

1.0.5

10 months ago

1.0.4

10 months ago