Skip to content

MikoDev-Sd/afk-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

💤 AFK Bot — Discord Away From Keyboard Bot

A lightweight, fully-featured Discord AFK bot built with discord.js v14. When a user sets themselves as AFK, the bot automatically notifies others who mention them, tracks how long they've been away, and welcomes them back when they return.


✨ Features

  • Set AFK status with a custom reason using !afk
  • Mention detection — instantly notifies the sender if they ping an AFK user
  • Auto-return — AFK status is automatically cleared when the user sends any message
  • Manual return — use !back to explicitly remove your AFK status
  • Duration tracking — shows exactly how long you were away
  • Nickname tagging — automatically prepends [AFK] to the user's server nickname (requires Manage Nicknames permission)
  • Auto-delete — bot replies auto-delete after a few seconds to keep channels clean
  • Embed-based UI — clean, color-coded Discord embeds for all responses

📸 Preview

Action Description
!afk studying Sets your status to AFK with reason "studying"
@mention an AFK user Bot warns the sender that the user is AFK
Send any message Bot auto-removes your AFK status and shows duration
!back Manually removes your AFK status

🚀 Getting Started

Prerequisites

1. Clone the Repository

git clone https://github.com/YOUR_USERNAME/afk-bot.git
cd afk-bot

2. Install Dependencies

npm install

3. Configure Environment Variables

Copy the example environment file and fill in your credentials:

cp .env.example .env

Open .env and add your bot token:

DISCORD_TOKEN=your_bot_token_here
CLIENT_ID=your_client_id_here

4. Set Up Your Discord Bot

  1. Go to the Discord Developer Portal
  2. Click New Application → give it a name
  3. Navigate to Bot → click Reset Token and copy the token
  4. Under Privileged Gateway Intents, enable:
    • Server Members Intent
    • Message Content Intent
  5. Navigate to OAuth2 → URL Generator
  6. Select scopes: bot
  7. Select permissions: Send Messages, Read Messages/View Channels, Manage Nicknames, Embed Links
  8. Copy the generated URL, paste it in your browser, and invite the bot to your server

5. Run the Bot

# Production
npm start

# Development (auto-restarts on file changes)
npm run dev

You should see:

✅ Logged in as YourBot#1234
📡 Serving 1 server(s)

📋 Commands

Command Description Example
!afk [reason] Set yourself as AFK with an optional reason !afk in a meeting
!back Manually remove your AFK status !back

Note: AFK status is also automatically removed when you send any message in the server.


📁 Project Structure

afk-bot/
├── src/
│   ├── index.js        # Bot entry point — client setup & event listeners
│   └── afkManager.js   # Core AFK logic — set, check, clear, format
├── .env.example        # Environment variable template
├── .gitignore          # Files excluded from version control
├── package.json        # Project metadata & dependencies
└── README.md           # You are here

⚙️ How It Works

  1. User runs !afk → their user ID is stored in a Map with the reason and timestamp.
  2. Someone sends a message with mentions → the bot checks each mentioned user against the AFK map.
  3. AFK user sends any message → the bot automatically clears their entry from the map and shows how long they were away.
  4. Nickname tagging → if the bot has Manage Nicknames permission and the member is below the bot in the role hierarchy, [AFK] is prepended to their nickname and removed on return.

🔒 Permissions Required

Permission Purpose
Send Messages Required to send AFK notifications
Embed Links Required to send embed messages
Read Message History Required to read messages for mention detection
Manage Nicknames (Optional) Adds [AFK] prefix to the user's nickname

🛠️ Built With


🤝 Contributing

Contributions, issues, and feature requests are welcome!

  1. Fork the repository
  2. Create a new branch: git checkout -b feature/your-feature-name
  3. Commit your changes: git commit -m "Add: your feature description"
  4. Push to the branch: git push origin feature/your-feature-name
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License — see the LICENSE file for details.


💡 Ideas for Future Improvements

  • Slash command (/afk) support
  • Per-server AFK prefix customization
  • Persistent AFK storage using a database (SQLite / MongoDB)
  • Auto-clear AFK after a configurable timeout
  • DM the AFK user a summary of who mentioned them while they were away

Made with ❤️ as a daily GitHub project.

About

A Discord bot that tracks AFK users, notifies mentioners, and auto-restores status when they return. Built with discord.js v14.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors