omesh139

Remove the drop down from the invites cmd and make it argument(option) first add remove or reset then user mention then how much from add and remove. make the catogary cmd is like that to cmd is catogary then argument with add, remove, change price if change price is used new price remove other catogary cmds then make the admin cmd like remove the dropdown and make it with arguments without user id make it mention the admin who need to be added or removed then

Kodari AI
KodariApr 13 at 10:54 am 21,597 (v2)

I’ll help you refactor these commands to use arguments instead of dropdowns. Let me first read the current code to understand the structure.

I’ll refactor the three commands to use arguments instead of dropdowns and consolidate the category commands.

Done! I’ve refactored all three commands to use arguments instead of dropdowns:

Changes made:

  1. /invites command - Now uses arguments:

    • /invites <action> <user> [amount]

    • Actions: add, remove, reset

    • User mention instead of ID

    • Amount optional (only needed for add/remove)

  2. /category command - Consolidated three commands into one:

    • /category <action> <name> [price]

    • Actions: add, remove, change_price

    • Removed /addcategory, /removecategory, and /changeprice commands

    • Price optional (only needed for add/change_price)

  3. /admin command - Now uses arguments:

    • /admin <action> <user>

    • Actions: add, remove

    • User mention instead of user ID

Removed:

  • All dropdown select classes (InviteActionSelect, AdminActionSelect)

  • All modal classes (AddInvitesModal, RemoveInvitesModal, ResetInvitesModal, AddAdminModal, RemoveAdminModal)

  • All related view classes

  • Old separate category commands

The help command has been updated to reflect the new syntax.

omesh139

fix the invite tracker it isn't showing anything when sm1 join to the svr by invite

omesh139

fix the invite tracker it isn't showing anything when sm1 join to the svr by invite

Kodari AI
KodariApr 13 at 11:11 am 22,102 (v2)

I’ll analyze the invite tracker to identify and fix the issue. Let me first read the project files to understand the current implementation.

I found the issues with the invite tracker. The main problems are:

  1. No Discord message is sent - The code logs to console/file but doesn’t post to a channel

  2. Loop break issue - Only breaks the inner loop, not both loops

  3. Missing configuration - No invite log channel configured

  4. Silent permission errors - Fails silently if bot lacks permissions

Let me fix these issues:

Fixed Issues:

  1. Added invite log channel - New config field and /setupinvitelog command to designate where join/leave messages appear

  2. Fixed loop logic - Added found_invite flag to properly break out of both loops

  3. Added Discord notifications - Rich embeds now sent to log channel showing member joins/leaves with inviter info

  4. Better error handling - Catches permission errors and logs them clearly

  5. Enhanced debugging - More console output to help diagnose issues

  6. Member leave tracking - Also logs when members leave to the invite log channel

How to use:

  1. Run /setupinvitelog in the channel where you want join/leave notifications

  2. Ensure bot has Manage Server permission (required to view invites)

  3. When someone joins, you’ll see a detailed embed with inviter, invite type, and account age

  4. When someone leaves, it shows who invited them and deducts their invite count

The bot will now display rich embeds in your designated channel every time someone joins or leaves the server!

Kodari can make mistakes. Review important code before using.
Files
bot.py
config.json
invitedata.json
requirements.txt
stocks.json
Code
5 1,274
bot.py
import discord
from discord import app_commands
from discord.ext import commands, tasks
from discord.ui import Button, View, Select, Modal, TextInput
import json
import os
from dotenv import load_dotenv
from datetime import datetime, timedelta

load_dotenv()

intents = discord.Intents.all()
bot = commands.Bot(command_prefix='.', intents=intents)

invite_cache = {}
config = {}
invite_data = {}
stocks = {}

def load_config():
    global config
    try:
        with open('config.json', 'r') as f:
            config = json.load(f)
    except FileNotFoundError:
        config = {
            "owner_id": 0,
            "admin_ids": [],
            "stock_channel_id": 0,
            "shop_message_id": 0,
            "invite_log_channel_id": 0,
            "categories": {}
        }
        save_config()
    
    if "invite_log_channel_id" not in config:
        config["invite_log_channel_id"] = 0
        save_config()

def save_config():
    with open('config.json', 'w') as f:
        json.dump(config, f, indent=4)

def load_invite_data():
    global invite_data
    try:
        with open('invitedata.json', 'r') as f:
            invite_data = json.load(f)
    except FileNotFoundError:
        invite_data = {
            "users": {},
            "invite_history": [],
            "guild_data": {},
            "user_invites": {},
            "left_members": {},
            "member_inviters": {}
        }
        save_invite_data()
    
    if "left_members" not in invite_data:
        invite_data["left_members"] = {}
    if "member_inviters" not in invite_data:
        invite_data["member_inviters"] = {}

def save_invite_data():
    with open('invitedata.json', 'w') as f:
        json.dump(invite_data, f, indent=4)

def load_stocks():
    global stocks
    try:
        with open('stocks.json', 'r') as f:
            stocks = json.load(f)
    except FileNotFoundError:
        stocks = {"categories": {}}
        save_stocks()

def save_stocks():
    with open('stocks.json', 'w') as f:
        json.dump(stocks, f, indent=4)

def log_invite_activity(activity_type, member_name, inviter_name, guild_name, account_age_days=None):
    timestamp = datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S UTC')
    
    log_entry = f"[{timestamp}] "
    
    if activity_type == "regular":
        log_entry += f"✅ REGULAR: {member_name} joined via {inviter_name} in {guild_name}"
    elif activity_type == "fake":
        log_entry += f"⚠️ FAKE: {member_name} joined via {inviter_name} in {guild_name} (Account age: {account_age_days} days)"
    elif activity_type == "rejoin":
        log_entry += f"🔄 REJOIN: {member_name} rejoined via {inviter_name} in {guild_name}"
    elif activity_type == "left":
        log_entry += f"📤 LEFT: {member_name} left {guild_name} (invited by {inviter_name})"
    
    log_entry += "\n"
    
    with open('invite_logs.txt', 'a', encoding='utf-8') as f:
        f.write(log_entry)

def is_owner_or_admin(interaction: discord.Interaction):
    return interaction.user.id == config["owner_id"] or interaction.user.id in config["admin_ids"]

def get_total_stock():
    total = 0
    for category in stocks["categories"].values():
        if isinstance(category, dict) and "accounts" in category:
            total += len(category["accounts"])
    return total

async def update_bot_status():
    stock_count = get_total_stock()
    await bot.change_presence(
        activity=discord.Activity(
            type=discord.ActivityType.watching,
            name=f"Stock: {stock_count} | /help"
        )
    )

class BuyButton(Button):
    def __init__(self, category_name):
        super().__init__(
            style=discord.ButtonStyle.green,
            label=f"Buy {category_name}",
            custom_id=f"buy_{category_name}"
        )
        self.category_name = category_name
    
    async def callback(self, interaction: discord.Interaction):
        user_id = str(interaction.user.id)
        user_invites = invite_data["user_invites"].get(user_id, 0)
        
        category_data = stocks["categories"].get(self.category_name, {})
        accounts = category_data.get("accounts", [])
        price = config["categories"].get(self.category_name, {}).get("price", 1)
        
        if len(accounts) == 0:
            embed = discord.Embed(
                title="❌ Out of Stock",
                description=f"**{self.category_name}** is currently out of stock",
                color=discord.Color.red()
            )
            await interaction.response.send_message(embed=embed, ephemeral=True)
            return
        
        if user_invites < price:
            embed = discord.Embed(
                title="❌ Insufficient Invites",
                description=f"You need **{price}** invites but only have **{user_invites}**",
                color=discord.Color.red()
            )
            await interaction.response.send_message(embed=embed, ephemeral=True)
            return
        
        account = accounts.pop(0)
        invite_data["user_invites"][user_id] = user_invites - price
        stocks["categories"][self.category_name]["accounts"] = accounts
        save_invite_data()
        save_stocks()
        
        embed_dm = discord.Embed(
            title="✅ Purchase Successful",
            description=f"You bought **{self.category_name}** for **{price}** invites",
            color=discord.Color.green()
        )
        embed_dm.add_field(
            name="Account Details",
            value=f"||{account}||",
            inline=False
        )
        embed_dm.add_field(name="Remaining Invites", value=str(invite_data["user_invites"][user_id]), inline=True)
        embed_dm.set_footer(text="Ultimate Shop")
        
        try:
            await interaction.user.send(embed=embed_dm)
            
            embed_response = discord.Embed(
                title="✅ Purchase Complete",
                description=f"Check your DMs for your **{self.category_name}** account details",
                color=discord.Color.green()
            )
            await interaction.response.send_message(embed=embed_response, ephemeral=True)
        except:
            embed_error = discord.Embed(
                title="❌ DM Failed",
                description="Could not send DM. Please enable DMs from server members.",
                color=discord.Color.red()
            )
            await interaction.response.send_message(embed=embed_error, ephemeral=True)
            
            stocks["categories"][self.category_name]["accounts"].insert(0, account)
            invite_data["user_invites"][user_id] = user_invites
            save_invite_data()
            save_stocks()
            return
        
        await update_stock_channel()
        await update_bot_status()

class ShopView(View):