toxicshadowx

Create a discord bot thats optimized to run on my pc that has commands like /strike (user) (reason) and it sends a message to the person you striked from the bot

Kodari AI
KodariFeb 2 at 11:25 pm 3,919 (v2)

I’ll create a Discord moderation bot with a strike command that DMs users.

StrikeModerationBot
A lightweight Discord moderation bot that allows moderators to issue strikes to users with documented reasons. The bot automatically sends direct messages to striked users notifying them of their violation, logs all strikes for record-keeping, and provides clean embed-based notifications. Optimized for efficient performance on personal computers with minimal resource usage.

Bot created! Here’s what you need to do:

Setup steps:

  1. Install Python dependencies: pip install -r requirements.txt

  2. Enable Server Members Intent and Message Content Intent in bot settings

  3. Copy your bot token and replace your_discord_bot_token_here in the .env file

  4. Invite bot to your server with these permissions: Send Messages, Use Slash Commands, Moderate Members

  5. Run: python bot.py

Usage:

  • /strike @user reason - Issues a strike and DMs the user

  • Only works for users with β€œModerate Members” permission

  • Sends professional embeds to both the user and moderator

  • Handles cases where users have DMs disabled

toxicshadowx

its mostly good but make it so when you strike someone it sends a embed message that everyone can see instead of the person who did the command

Kodari AI
KodariFeb 2 at 11:43 pm 2,639 (v2)

I’ll read the bot.py file to see the current strike implementation and modify it to send a public embed message.

I’ll modify the strike command to send a public embed message that everyone can see instead of making it ephemeral (private).

Changed the strike confirmation message to be public - removed ephemeral=True from the final send_message call so everyone in the channel can see when a strike is issued.

toxicshadowx

Perfect now make it so when you strike someone it gives that person a role depending what strike they are on so for example if you strike someone they get the role "Strike 1" and if they get striked again its "Strike 2" and again "Strike 3"

Kodari AI
KodariFeb 2 at 11:47 pm 4,295 (v2)

I’ll read the current bot.py file to understand the strike system and then add role assignment functionality.

I’ll modify the bot to track strikes and assign roles accordingly.

Done! The bot now assigns strike roles based on strike count:

  • First strike β†’ β€œStrike 1” role (yellow)

  • Second strike β†’ β€œStrike 2” role (orange)

  • Third strike β†’ β€œStrike 3” role (red)

Key features:

  • Automatically creates strike roles if they don’t exist

  • Removes previous strike role before adding new one

  • Tracks strikes per user per server

  • Shows strike count in both DM and confirmation messages

  • Caps at Strike 3 (getting more strikes keeps the Strike 3 role)

Important: Make sure your bot has the β€œManage Roles” permission in your Discord server for this to work!

toxicshadowx

Add a warning system and a logging system so you can do /warn user and reason and /logs for all logs of every strike and warning

Kodari AI
KodariApr 4 at 6:53 am 6,518 (v2)

I’ll read the existing bot files to understand the current structure, then add a warning and logging system.

I’ll add a comprehensive warning system and logging system to your Discord bot. This will include persistent storage of both strikes and warnings, a /warn command, and a /logs command to view all moderation actions.

Added complete warning and logging system with the following features:

New Commands:

  • /warn user reason - Issues a warning to a user (sends DM notification and logs the action)

  • /logs [user] - Views all moderation logs; optionally filter by specific user

Features:

  • Persistent storage in moderation_logs.json - all warnings and strikes are saved and loaded on bot restart

  • Detailed log entries with timestamps, moderator info, reasons, and action types

  • Rich embed displays for both warnings and log viewing

  • Automatic pagination if logs exceed 25 entries

  • Both strikes and warnings are now permanently logged

toxicshadowx

Make it so when you do /logs everyone can see it not just the person doing the command and make it so when you do /warn you get a role Warning 1 and Warning 2 and Warning 3 and add a command to remove strikes and warning which also auto remove the roles for example someone has a strike you can do /strikeremove or something optimal and it will remove the strike and log that it has been removed and sent a message to the person with a strike that the strike has been removed and goes down by 1 strike or warning every time its used and also add a /ping command

Kodari AI
KodariApr 4 at 7:01 am 11,508 (v2)

I’ll read the existing bot files to understand the current structure and make the necessary changes.

I’ll update the bot to make all those changes:

All requested features have been implemented:

  • /logs now shows publicly (removed ephemeral flags)

  • /warn now assigns Warning 1/2/3 roles automatically

  • /strikeremove removes strikes, updates roles, logs the action, and DMs the user

  • /warningremove removes warnings, updates roles, logs the action, and DMs the user

  • /ping command added to check bot latency

toxicshadowx

Add a simple /say command so you can make the bot say anything

Kodari AI
KodariApr 4 at 9:57 am 5,940 (v2)

I’ll read the existing bot files to understand the current structure, then add a /say slash command.

I’ll add a /say command that allows the bot to repeat any message. I’ll place it with the other commands and add a permission check to prevent abuse.

Added /say command that allows users with moderate permissions to make the bot say anything. The command requires the β€œModerate Members” permission to prevent abuse, and sends a confirmation message only visible to the command user.

Kodari can make mistakes. Review important code before using.
Files
bot.py
README.md
requirements.txt
Code
3 704
bot.py
import discord
from discord import app_commands
from discord.ext import commands
import os
from dotenv import load_dotenv
import logging
from datetime import datetime
import json

load_dotenv()

logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')

intents = discord.Intents.default()
intents.message_content = True
intents.members = True

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

user_strikes = {}
user_warnings = {}
moderation_logs = {}

LOGS_FILE = 'moderation_logs.json'

def load_logs():
    global moderation_logs, user_strikes, user_warnings
    try:
        if os.path.exists(LOGS_FILE):
            with open(LOGS_FILE, 'r') as f:
                data = json.load(f)
                moderation_logs = data.get('logs', {})
                user_strikes = {}
                for guild_id_str, users in data.get('strikes', {}).items():
                    guild_id = int(guild_id_str)
                    user_strikes[guild_id] = {}
                    for user_id_str, count in users.items():
                        user_strikes[guild_id][int(user_id_str)] = count
                user_warnings = {}
                for guild_id_str, users in data.get('warnings', {}).items():
                    guild_id = int(guild_id_str)
                    user_warnings[guild_id] = {}
                    for user_id_str, count in users.items():
                        user_warnings[guild_id][int(user_id_str)] = count
                logging.info(f'Loaded moderation logs from {LOGS_FILE}')
    except Exception as e:
        logging.error(f'Failed to load logs: {e}')
        moderation_logs = {}
        user_strikes = {}
        user_warnings = {}

def save_logs():
    try:
        data = {
            'logs': moderation_logs,
            'strikes': {str(guild_id): {str(user_id): count for user_id, count in users.items()} 
                       for guild_id, users in user_strikes.items()},
            'warnings': {str(guild_id): {str(user_id): count for user_id, count in users.items()} 
                        for guild_id, users in user_warnings.items()}
        }
        with open(LOGS_FILE, 'w') as f:
            json.dump(data, f, indent=4)
        logging.info(f'Saved moderation logs to {LOGS_FILE}')
    except Exception as e:
        logging.error(f'Failed to save logs: {e}')

def add_log_entry(guild_id: int, user_id: int, moderator_id: int, action_type: str, reason: str, additional_info: dict = None):
    guild_id_str = str(guild_id)
    user_id_str = str(user_id)
    
    if guild_id_str not in moderation_logs:
        moderation_logs[guild_id_str] = {}
    
    if user_id_str not in moderation_logs[guild_id_str]:
        moderation_logs[guild_id_str][user_id_str] = []
    
    log_entry = {
        'timestamp': datetime.utcnow().isoformat(),
        'action': action_type,
        'reason': reason,
        'moderator_id': moderator_id
    }
    
    if additional_info:
        log_entry.update(additional_info)
    
    moderation_logs[guild_id_str][user_id_str].append(log_entry)
    save_logs()

@bot.event
async def on_ready():
    logging.info(f'Bot is ready! Logged in as {bot.user}')
    load_logs()
    try:
        synced = await bot.tree.sync()
        logging.info(f'Synced {len(synced)} command(s)')
    except Exception as e:
        logging.error(f'Failed to sync commands: {e}')

async def get_or_create_strike_role(guild: discord.Guild, strike_number: int):
    role_name = f"Strike {strike_number}"
    role = discord.utils.get(guild.roles, name=role_name)
    
    if role is None:
        try:
            role = await guild.create_role(
                name=role_name,
                color=discord.Color.red() if strike_number == 3 else discord.Color.orange() if strike_number == 2 else discord.Color.yellow(),
                reason="Strike role created automatically"
            )
            logging.info(f'Created role: {role_name}')
        except discord.Forbidden:
            logging.error(f'Missing permissions to create role: {role_name}')
            return None
        except Exception as e:
            logging.error(f'Failed to create role {role_name}: {e}')
            return None
    
    return role

async def get_or_create_warning_role(guild: discord.Guild, warning_number: int):
    role_name = f"Warning {warning_number}"
    role = discord.utils.get(guild.roles, name=role_name)
    
    if role is None:
        try:
            role = await guild.create_role(
                name=role_name,
                color=discord.Color.dark_orange() if warning_number == 3 else discord.Color.gold() if warning_number == 2 else discord.Color.yellow(),
                reason="Warning role created automatically"
            )
            logging.info(f'Created role: {role_name}')
        except discord.Forbidden:
            logging.error(f'Missing permissions to create role: {role_name}')
            return None
        except Exception as e:
            logging.error(f'Failed to create role {role_name}: {e}')
            return None
    
    return role

async def remove_previous_strike_roles(member: discord.Member):
    strike_roles = [role for role in member.roles if role.name in ["Strike 1", "Strike 2", "Strike 3"]]
    for role in strike_roles:
        try:
            await member.remove_roles(role)
            logging.info(f'Removed role {role.name} from {member}')
        except Exception as e:
            logging.error(f'Failed to remove role {role.name} from {member}: {e}')

async def remove_previous_warning_roles(member: discord.Member):
    warning_roles = [role for role in member.roles if role.name in ["Warning 1", "Warning 2", "Warning 3"]]
    for role in warning_roles:
        try:
            await member.remove_roles(role)
            logging.info(f'Removed role {role.name} from {member}')
        except Exception as e:
            logging.error(f'Failed to remove role {role.name} from {member}: {e}')

@bot.tree.command(name='ping', description='Check the bot latency')
async def ping(interaction: discord.Interaction):
    latency = round(bot.latency * 1000)
    embed = discord.Embed(
        title='πŸ’ͺ Godly Ping',
        description=f'Bot latency: **{latency}ms**',
        color=discord.Color.green()
    )
    await interaction.response.send_message(embed=embed)

@bot.tree.command(name='strike', description='Issue a strike to a user')
@app_commands.describe(user='The user to strike', reason='The reason for the strike')
async def strike(interaction: discord.Interaction, user: discord.Member, reason: str):
    if not interaction.user.guild_permissions.moderate_members:
        await interaction.response.send_message('You do not have permission to use this command.', ephemeral=True)
        return
    
    if user.bot:
        await interaction.response.send_message('You cannot strike a bot.', ephemeral=True)
        return
    
    if user.id == interaction.user.id:
        await interaction.response.send_message('You cannot strike yourself.', ephemeral=True)
        return
    
    guild_id = interaction.guild.id
    user_id = user.id
    
    if guild_id not in user_strikes:
        user_strikes[guild_id] = {}
    
    if user_id not in user_strikes[guild_id]:
        user_strikes[guild_id][user_id] = 0
    
    user_strikes[guild_id][user_id] += 1
    current_strikes = user_strikes[guild_id][user_id]
    
    if current_strikes > 3:
        current_strikes = 3
        user_strikes[guild_id][user_id] = 3