# discord.js-presence

> Some discord.js presence toolset, and lightweight. Good for beginners.

Latest version **1.1.2** (published 2023-08-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install discord.js-presence
pnpm add discord.js-presence
yarn add discord.js-presence
bun add discord.js-presence
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2023-08-02 |
| First published | 2023-08-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 19.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | cosmo |
| Maintainers | cosmocreates |
| Keywords | discord-js, discord-bot, discordjs, presence, discord |

## Links

- npm: https://www.npmjs.com/package/discord.js-presence
- npm.io page: https://npm.io/package/discord.js-presence

## Recent versions

- 1.1.2 (latest) — 2023-08-02
- 1.0.6 — 2023-08-02
- 1.0.5 — 2023-08-02
- 1.0.4 — 2023-08-02

## README

# 📅 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.

```js
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
```js
PresenceToolkit.setStatus(newClient, 'dnd')
```
![output.png](https://i.ibb.co/tB9sW0X/image.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

```js
PresenceToolkit.setActivity(client, 'over every person', ActivityType.Watching)
```

![output.png](https://i.ibb.co/Cvt61LG/image.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

```js
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

```js
PresenceToolkit.setPlaceholderActivity(newClient, 'nothing, really', ActivityType.Playing);
```

![gifdemo.gif](https://i.ibb.co/sbbcWDC/10271572e307084848c40a72f03971fa.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

```js
✅ PresenceToolkit.unregisterActivities(newClient, [0, 1, 2]);
```

```js
✅ PresenceToolkit.unregisterActivities(newClient, ['Some activity to find', 'Some other activity to find']);
```

```js
⛔ 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

```js
⛔ PresenceToolkit.changeCyclingSpeed(newClient, 5);
```

```js
✅⚠️ PresenceToolkit.changeCyclingSpeed(newClient, 7);
```

```js
✅ PresenceToolkit.changeCyclingSpeed(newClient, 10);
```

- ### startCycling

#### Rundown

Arguments: `client`\*

The `startCycling()` function starts cycling through registered activities/presences.

#### Example

```js
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](https://i.ibb.co/31HwmzB/97b2b8c726bb2f74f934ddf50c3bfe77.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

```js
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

```js
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

```js
PresenceToolkit.cycleActivity(newClient);
```

- ### setPlaceholderEnabled

#### Rundown

Arguments: `client`\*, `bool`\*

The `setPlaceholderEnabled()` function controls on whether the placeholder status is enabled or not.

#### Example

```js
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

```js
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`!

---
_Source: https://npm.io/package/discord.js-presence · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
