Files
.gitignore
bot.py
config.json
README.md
requirements.txt
Code
5 838
bot.py
import discord
from discord.ext import commands, tasks
from discord import app_commands
import os
from dotenv import load_dotenv
import json
import logging
from datetime import datetime, timedelta
import random
import asyncio
from io import StringIO
load_dotenv()
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
def load_config():
try:
with open('config.json', 'r') as f:
return json.load(f)
except FileNotFoundError:
logger.warning("config.json not found, using defaults")
return {
"prefix": "/",
"admin_role_id": None,
"verified_role_id": None,
"vouch_channel": None,
"log_channel": None,
"welcome_channel": None
}
def load_data(filename):
try:
with open(filename, 'r') as f:
return json.load(f)
except FileNotFoundError:
return {}
def save_data(filename, data):
with open(filename, 'w') as f:
json.dump(data, f, indent=4)
config = load_config()
stock = load_data('stock.json')
if not stock:
stock = {
"mc_shared": [],
"mc_fp": [],
"roblox": [],
"microsoft": []
}
save_data('stock.json', stock)
vouches = load_data('vouches.json')
if not vouches:
vouches = {}
save_data('vouches.json', vouches)
blacklist = load_data('blacklist.json')
if not blacklist:
blacklist = []
save_data('blacklist.json', blacklist)
claims = load_data('claims.json')
if not claims:
claims = {}
save_data('claims.json', claims)
staff_stats = load_data('staff_stats.json')
if not staff_stats:
staff_stats = {}
save_data('staff_stats.json', staff_stats)
deleted_messages = []
intents = discord.Intents.all()
bot = commands.Bot(command_prefix=config['prefix'], intents=intents)
def is_admin():
async def predicate(interaction: discord.Interaction):
if interaction.user.guild_permissions.administrator:
return True
if config.get('admin_role_id'):
admin_role = interaction.guild.get_role(config['admin_role_id'])
if admin_role in interaction.user.roles:
return True
await interaction.response.send_message("โ You need admin permissions to use this command.", ephemeral=True)
return False
return app_commands.check(predicate)
def is_verified():
async def predicate(interaction: discord.Interaction):
if config.get('verified_role_id'):
verified_role = interaction.guild.get_role(config['verified_role_id'])
if verified_role not in interaction.user.roles:
await interaction.response.send_message("โ You must be verified to use this command. Use `/verify` first.", ephemeral=True)
return False
return True
return app_commands.check(predicate)
def is_blacklisted():
async def predicate(interaction: discord.Interaction):
if interaction.user.id in blacklist:
await interaction.response.send_message("โ You are blacklisted from using marketplace features.", ephemeral=True)
return False
return True
return app_commands.check(predicate)
@bot.event
async def on_ready():
logger.info(f'VaultCord is ready! Logged in as {bot.user.name} (ID: {bot.user.id})')
try:
synced = await bot.tree.sync()
logger.info(f"Synced {len(synced)} slash commands")
except Exception as e:
logger.error(f"Failed to sync commands: {e}")
await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name="the Vault ๐"))
@bot.event
async def on_member_join(member):
if config.get('welcome_channel'):
channel = bot.get_channel(config['welcome_channel'])
if channel:
embed = discord.Embed(
title="๐ Welcome to VaultCord!",
description=f"Welcome {member.mention}! Please use `/verify` to gain access to the server.",
color=discord.Color.blue(),
timestamp=datetime.utcnow()
)
embed.set_thumbnail(url=member.avatar.url if member.avatar else member.default_avatar.url)
embed.add_field(name="Member Count", value=f"#{member.guild.member_count}")
await channel.send(embed=embed)
@bot.event
async def on_message_delete(message):
if message.author.bot:
return
deleted_messages.append({
"author": message.author,
"content": message.content,
"channel": message.channel,
"time": datetime.utcnow(),
"mentions": message.mentions
})
if len(message.mentions) > 0:
embed = discord.Embed(
title="๐ป Ghost Ping Detected",
description=f"**Author:** {message.author.mention}\n**Channel:** {message.channel.mention}",
color=discord.Color.red(),
timestamp=datetime.utcnow()
)
embed.add_field(name="Deleted Message", value=message.content[:1024] if message.content else "*No content*", inline=False)
embed.add_field(name="Mentioned Users", value=" ".join([user.mention for user in message.mentions]), inline=False)
if config.get('log_channel'):
log_channel = bot.get_channel(config['log_channel'])
if log_channel:
await log_channel.send(embed=embed)
@bot.tree.command(name="verify", description="Verify yourself to access the server")
async def verify(interaction: discord.Interaction):
if config.get('verified_role_id'):
verified_role = interaction.guild.get_role(config['verified_role_id'])
if verified_role in interaction.user.roles:
await interaction.response.send_message("โ
You are already verified!", ephemeral=True)
return
view = VerifyView()
embed = discord.Embed(
title="๐ VaultCord Verification",
description="Click the button below to verify and gain access to the server.",
color=discord.Color.green()
)
await interaction.response.send_message(embed=embed, view=view, ephemeral=True)
class VerifyView(discord.ui.View):
def __init__(self):
super().__init__(timeout=180)
@discord.ui.button(label="โ
Verify Me", style=discord.ButtonStyle.green)
async def verify_button(self, interaction: discord.Interaction, button: discord.ui.Button):
if config.get('verified_role_id'):
verified_role = interaction.guild.get_role(config['verified_role_id'])
if verified_role:
await interaction.user.add_roles(verified_role)
await interaction.response.send_message("โ
You have been verified! Welcome to VaultCord.", ephemeral=True)
logger.info(f"{interaction.user.name} verified successfully")
else:
await interaction.response.send_message("โ Verified role not found. Please contact an admin.", ephemeral=True)
else:
await interaction.response.send_message("โ Verification is not set up yet. Please contact an admin.", ephemeral=True)
@bot.tree.command(name="stock", description="View available account stock")
@app_commands.checks.cooldown(1, 30, key=lambda i: i.user.id)
async def stock_cmd(interaction: discord.Interaction):
embed = discord.Embed(
title="๐ฆ VaultCord Stock",
description="Current available accounts in stock",