by wajahat

Verified Template

Discord Activity Rank & Monitor Bot That Kicks Inactive Members

Test this app for free
870
import discord
from discord.ext import commands
import os
from datetime import datetime, timedelta
import logging

# Set up logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

# Retrieve the Discord bot token from the environment variable
BOT_TOKEN = os.environ['DISCORD_BOT_TOKEN']

# Define intents
intents = discord.Intents.default()
intents.messages = True  # Subscribe to the messages intent to track last message activity.
intents.members = True  # Subscribe to the privileged members intent.

bot = commands.Bot(command_prefix='!', intents=intents)

# In-memory storage for inactivity criteria and channel message history
inactivity_criteria = {}
channel_message_history = {}
Get full code

Created: | Last Updated:

This Discord activity bot monitors and ranks member activity within a server. It allows administrators to rank inactivity criteria in days or minutes using command !setinactivity x minutes or !setinactivity x days. Inactive users can be kicked based on the criteria set by the administrators using command !kickinactive. App requires 'DISCORD_BOT_TOKEN' environment secret. And you need to give the bot following permissions on discord website. Read Message History: To fetch past messages and determine member activity. Kick Members: To remove inactive members from the server. Read Messages / View channels: To read latest message of user.

Here's a step-by-step guide for using the Discord Activity Rank & Monitor Bot template that kicks inactive members:

Introduction

This template provides a Discord bot that monitors member activity within a server. It allows administrators to set inactivity criteria and kick inactive members based on those criteria.

Getting Started

  1. Click "Start with this Template" to begin using this template in the Lazy Builder interface.

Initial Setup

  1. Set up the required environment secret:
  2. In the Lazy Builder, navigate to the Environment Secrets tab.
  3. Add a new secret with the key DISCORD_BOT_TOKEN.
  4. To obtain the Discord Bot Token:
    • Go to the Discord Developer Portal (https://discord.com/developers/applications).
    • Create a new application or select an existing one.
    • Navigate to the "Bot" section and click "Add Bot" if you haven't already.
    • Under the bot's token, click "Copy" to copy the token.
  5. Paste the copied token as the value for the DISCORD_BOT_TOKEN secret in Lazy Builder.

  6. Set up bot permissions on Discord:

  7. In the Discord Developer Portal, go to your application's "OAuth2" section.
  8. Under "Scopes", select "bot".
  9. Under "Bot Permissions", select the following:
    • Read Message History
    • Kick Members
    • Read Messages / View Channels
  10. Copy the generated OAuth2 URL and use it to invite the bot to your Discord server.

Test the Bot

  1. Click the "Test" button in the Lazy Builder to deploy and start the bot.

Using the Bot

Once the bot is running, you can use the following commands in your Discord server:

  1. Set inactivity criteria:
  2. Use the command !setinactivity <period> <unit> where:
    • <period> is a number
    • <unit> is either "days" or "minutes"
  3. Example: !setinactivity 3 days or !setinactivity 30 minutes

  4. Kick inactive members:

  5. Use the command !kickinactive to kick members who meet the inactivity criteria.

Note: Only users with administrator permissions in the Discord server can use these commands.

Integrating the Bot

This bot runs as a standalone application within your Discord server. There are no additional integration steps required beyond inviting the bot to your server and using its commands.

Technologies

Discord Automation & Bots Discord Automation & Bots

Similar templates

We found some blogs you might like...