Добавить WL verify bot/bot_verify.py

This commit is contained in:
NIKITIK0 2026-10-16 15:01:30 +03:00
parent ee6f0c439a
commit beb86ce468

114
WL verify bot/bot_verify.py Normal file
View File

@ -0,0 +1,114 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
TOKEN = "ваш токен"
import discord
from discord.ext import commands
from discord import app_commands
import json
import os
# =====================================================
# 📁 НАСТРОЙКИ (JSON)
# =====================================================
SETTINGS_FILE = "settings.json"
def load_settings():
if not os.path.exists(SETTINGS_FILE):
return {}
with open(SETTINGS_FILE, 'r', encoding='utf-8') as f:
try:
return json.load(f)
except:
return {}
def save_settings(data):
with open(SETTINGS_FILE, 'w', encoding='utf-8') as f:
json.dump(data, f, indent=4, ensure_ascii=False)
def get_setting(key):
return load_settings().get(key)
def set_setting(key, value):
data = load_settings()
data[key] = value
save_settings(data)
# =====================================================
# 🤖 БОТ
# =====================================================
intents = discord.Intents.default()
intents.guilds = True
intents.members = True
class VerifyBot(commands.Bot):
def __init__(self):
super().__init__(command_prefix='!', intents=intents)
async def setup_hook(self):
await self.tree.sync()
print("✅ Слэш-команды синхронизированы!")
bot = VerifyBot()
@bot.event
async def on_ready():
print(f'✅ Бот {bot.user} запущен!')
await bot.change_presence(activity=discord.Activity(
type=discord.ActivityType.watching,
name="✅ /verify"
))
# =====================================================
# 🔧 КОМАНДЫ НАСТРОЙКИ
# =====================================================
@bot.tree.command(name="verify-setrole", description="Установить роль для новых пользователей (не ботов)")
@app_commands.default_permissions(administrator=True)
@app_commands.describe(role="Роль для выдачи")
async def verify_setrole(interaction: discord.Interaction, role: discord.Role):
set_setting('verify_role', str(role.id))
await interaction.response.send_message(f'✅ Роль для верификации: {role.mention}', ephemeral=True)
@bot.tree.command(name="verify-setbotrole", description="Установить роль для ботов (опционально)")
@app_commands.default_permissions(administrator=True)
@app_commands.describe(role="Роль для ботов")
async def verify_setbotrole(interaction: discord.Interaction, role: discord.Role):
set_setting('bot_role', str(role.id))
await interaction.response.send_message(f'✅ Роль для ботов: {role.mention}', ephemeral=True)
# =====================================================
# 👤 СОБЫТИЕ ПРИ ЗАХОДЕ
# =====================================================
@bot.event
async def on_member_join(member: discord.Member):
if member.bot:
bot_role_id = get_setting('bot_role')
if bot_role_id:
role = member.guild.get_role(int(bot_role_id))
if role:
await member.add_roles(role)
return
verify_role_id = get_setting('verify_role')
if verify_role_id:
role = member.guild.get_role(int(verify_role_id))
if role:
await member.add_roles(role)
print(f'✅ Выдана роль {role.name} для {member}')
# =====================================================
# 🚀 ЗАПУСК
# =====================================================
if __name__ == "__main__":
try:
bot.run(TOKEN)
except discord.LoginFailure:
print("❌ Неверный токен!")
except Exception as e:
print(f"❌ Ошибка: {e}")