Discord Activity Monitor Bot

 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 = {}

About this template

This Discord bot monitors 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.

Introduction to the Discord Activity Monitor Bot Template

Welcome to the step-by-step guide on how to use the Discord Activity Monitor Bot template on the Lazy platform. This template allows you to create a Discord bot that monitors member activity within a server and enables administrators to set inactivity criteria and kick inactive members based on these criteria. The bot uses commands like !setinactivity to set the inactivity period and !kickinactive to remove inactive members.

Clicking Start with this Template

To begin building your Discord Activity Monitor Bot, click on the "Start with this Template" button. This will pre-populate the code in the Lazy Builder interface, so you won't need to copy, paste, or delete any code.

Initial setup: Adding Environment Secrets

Before you can test and deploy your bot, you need to set up an environment secret within the Lazy Builder:

  • Go to the Environment Secrets tab within the Lazy Builder.
  • Create a new secret named DISCORD_BOT_TOKEN.
  • Enter the value for your Discord bot token, which you can obtain from the Discord Developer Portal after creating your bot application.

Ensure that your bot has the following permissions on the 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 the latest message of a user.

Test: Pressing the Test Button

Once you have set up the environment secret, press the "Test" button. This will begin the deployment of your app and launch the Lazy CLI. The bot will start running on the Lazy platform, and you will not need to install any libraries or set up your environment.

Using the App

After deploying your bot, it will be active on your Discord server. Use the following commands within your server to manage member activity:

  • !setinactivity [number] [days/minutes] - Sets the inactivity criteria for the server. For example, !setinactivity 7 days will set the inactivity threshold to 7 days.
  • !kickinactive - Kicks members who have been inactive longer than the set criteria.

When you use the !kickinactive command, the bot will check the activity of each member and kick those who meet the inactivity criteria. It will also send a message in the server with details about the kicked members.

Integrating the App

If you wish to integrate this bot with other tools or services, you may need to provide the bot's server link or API endpoints. However, since this template is designed to work within a Discord server, no additional external integration steps are required for the bot to function as intended.

By following these steps, you can easily set up and use the Discord Activity Monitor Bot on your server to manage member activity and ensure an active community.

Category
Technology
Last published
July 26, 2024

More templates like this

AlphaBot Financial Summary

AlphaBot Financial Summary: A Discord bot that utilizes the Alpha Vantage API to provide AI-generated summaries of income statements, balance sheets, and cash flow for renowned US companies.

Discord

Discord Moderation Bot

The Discord bot monitors all messages in the server. If a message contains profanity, the bot deletes it and sends a warning to the channel. The bot also notifies the host about the deletion via a direct message. Additionally, the bot outputs a helpful error message to a channel if there is a permissions error, guiding the server admin to enable the required permission in the Discord Developer portal.

Discord
Python
Flask

Discord Bot

This powerful app skeleton is a great starting place for a Discord bot

Discord
Home
/
Discord Activity Monitor Bot