# discord-afk-js

> discord-afk-js package is a convenient tool for creating AFK commands without the need for a database

Latest version **1.5.3** (published 2024-10-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install discord-afk-js
pnpm add discord-afk-js
yarn add discord-afk-js
bun add discord-afk-js
```

## Health

**Score 45/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities; has provenance; high quality score.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.5.3 |
| Published | 2024-10-14 |
| First published | 2023-04-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=18 |
| Dependencies | 7 |
| Unpacked size | 20.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 3 |
| Author | brokenedtz |
| Maintainers | brokenedtz |
| Keywords | discord, discord-afk, bot, bots, discord-bot, discord.js, afks, afk, discord-afk-js, nodatabase, nodb |

## Links

- npm: https://www.npmjs.com/package/discord-afk-js
- Repository: https://github.com/SITCommunity/discord-afk-js
- Homepage: https://cyrateam.xyz/discord-afk-js
- Issues: https://github.com/SITCommunity/discord-afk-js/issues
- Funding: https://github.com/SITCommunity/discord-afk-js?sponsor
- npm.io page: https://npm.io/package/discord-afk-js

## Dependencies (7)

- [boxen](https://npm.io/package/boxen.md) ^8.0.1
- [chalk](https://npm.io/package/chalk.md) ^5.3.0
- [tslib](https://npm.io/package/tslib.md) ^2.7.0
- [moment](https://npm.io/package/moment.md) ^2.29.4
- [semver](https://npm.io/package/semver.md) ^7.6.0
- [semver-diff](https://npm.io/package/semver-diff.md) ^4.0.0
- [package-json](https://npm.io/package/package-json.md) ^10.0.1

## Recent versions

- 1.5.3 (latest) — 2024-10-14
- 10.0.1 (database) — 2024-06-11
- 1.5.2 — 2024-10-11
- 1.5.1 — 2024-10-11
- 10.0.0 — 2024-06-11
- 1.5.0 — 2023-10-18
- 1.4.9 — 2023-10-18
- 1.4.8 — 2023-09-01
- 1.4.7 — 2023-07-21
- 1.4.6 — 2023-06-02
- 1.4.5 — 2023-05-26
- 1.4.4 — 2023-05-26
- 1.4.3 — 2023-05-20
- 1.4.2 — 2023-05-20
- 1.4.1 — 2023-05-18
- … 8 more at https://npm.io/package/discord-afk-js/versions

## README

<div align="center">
  <p>
    <a target="_blank" href="https://www.npmjs.com/package/discord-afk-js" rel="noopener noreferrer"><img src="https://nodei.co/npm/discord-afk-js.png?downloads=true&downloadRank=true&stars=true"></a>
  </p>
  <p>
    <a target="_blank" href="https://nodejs.org/" rel="noopener noreferrer"><img alt="node-current" src="https://img.shields.io/node/v/distube"></a>
    <a target="_blank" href="https://www.npmjs.com/package/discord-afk-js" rel="noopener noreferrer"><img alt="npm" src="https://img.shields.io/npm/dt/discord-afk-js"></a>
    <a target="_blank" href="https://www.npmjs.com/package/discord-afk-js" rel="noopener noreferrer"><img alt="npm latest" src="https://img.shields.io/npm/v/discord-afk-js/latest?color=blue&label=discord-afk-js%40latest&logo=npm"></a>
    <a target="_blank" href="https://github.com/skick1234/CyraTeam/discord-afk-js" rel="noopener noreferrer"><img alt="GitHub Repo stars" src="https://img.shields.io/github/stars/CyraTeam/discord-afk-js"></a>
    <a target="_blank" href="https://discord.gg/qpT2AeYZRN" rel="noopener noreferrer"><img alt="Discord" src="https://img.shields.io/discord/984857299858382908?label=CyraTeam&logo=discord"></a>
    <a target="_blank" href="https://github.com/CyraTeam/discord-afk-js" rel="noopener noreferrer"><img alt="Visitor" src="https://api.visitorbadge.io/api/visitors?path=https%3A%2F%2Fgithub.com%2FCyraTeam%2Fdiscord-afk-js&countColor=%2337d67a&style=flat"></a>
    <a target="_blank" href="https://github.com/CyraTeam/discord-afk-js/issues" rel="noopener noreferrer"><img alt="Issues" src="https://img.shields.io/github/issues/CyraTeam/discord-afk-js"></a>
    <a target="_blank" href="https://github.com/CyraTeam/discord-afk-js" rel="noopener noreferrer"><img alt="Commit" src="https://img.shields.io/github/commit-activity/y/CyraTeam/discord-afk-js?label=Commit%20Activity&logo=github"></a>
    <a target="_blank" href="https://codecov.io/gh/CyraTeam/discord-afk-js"><img src="https://codecov.io/gh/CyraTeam/discord-afk-js/graph/badge.svg?token=98ZKDNNXVE"/></a> 
  </p>
</div>

# discord-afk-js

**[discord-afk-js](https://www.npmjs.com/package/discord-afk-js?activeTab=readme)** is a JavaScript library created to facilitate the management of AFK (Away From Keyboard) status within Discord bots. This library is designed to simplify the process of tracking and handling AFK users in a Discord server without the need for an external database.

# Requirements

- [NodeJS](https://nodejs.org) 18.x or higher

# Installation

To start using **discord-afk-js**, you can install it through npm, the Node.js package manager. Open your terminal and run the following command:

```bash
npm install discord-afk-js
```

# Usage

**discord-afk-js** offers a straightforward way to manage AFK users in your Discord bot. Below is an example of how to utilize the **AfkClient** class:

```javascript
const { AfkClient } = require('discord-afk-js');

// Create an instance of AfkClient
const afk = new AfkClient();

// ================================================================

// Checking if a user is AFK without time
afk.setUser({ id: 'id1', reason: 'Afk Playing Game' });

const [reason, time] = await afk.getReason('id1');

if (afk.findUser('id1')) {
  console.log('User is marked as AFK'); // console: User is marked as AFK
  console.log('AFK Message:', `${reason} ${time}`); // console: AFK Message: Afk Playing Game a few seconds ago
}

// ================================================================

// Adding a user to AFK status without reason
afk.setUser({ id: 'id2' });

if (afk.findUser('id2')) {
  console.log('User is marked as AFK'); // console: User is marked as AFK
  const [reason, time] = await afk.getReason('id2');

  console.log('AFK Message:', `${reason} ${time}`); // console: AFK Message: No Reason a few seconds ago
}

// ================================================================

// Get reason without array
afk.setUser({ id: 'id3' });
const reason = await afk.getReason('id3');

console.log(reason); // console: No Reason a few seconds ago

//================================================================

// Removing a user from AFK status
afk.removeUser('user123');
```

In the code snippet above, we start by importing the **AfkClient** class. After creating an instance of this class, we demonstrate how to add a user to the AFK list, check their AFK status, and remove them from AFK status.

# Changelog | Migrating to discord-afk-js

```diff
+ change afk to AfkClient for import
+ afk.addUser() -> afk.setUser()
+ afk.deleteUser() -> afk.removeUser()
+ afk.getReason()
```

# License

This project is open-source and is licensed under the MIT License. You can find more details about the license in the [LICENSE.md](https://github.com/CyraTeam/discord-afk-js/blob/main/LICENSE) file included in the project.

With this comprehensive readme, you have a clear and detailed guide on how to use the **discord-afk-js** library to manage AFK status in your Discord bot.

# Discord Servers

<a href="https://discord.gg/qpT2AeYZRN" target="_blank" rel="noopener noreferrer"><img alt="Discord" src="https://img.shields.io/discord/984857299858382908?label=CyraTeam&logo=discord"></a>

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