oxygenyt/bot
0
1import discord2from discord.ext import commands3import requests4import os5from flask import Flask6from threading import Thread7 8# --- 1. WEB SERVER ---9app = Flask('')10 11@app.route('/')12def home():13 return "Bot status: System is checking credentials..."14 15def run_flask():16 app.run(host='0.0.0.0', port=7860)17 18# --- 2. BOT CONFIGURATION ---19intents = discord.Intents.default()20intents.message_content = True 21intents.members = True 22intents.presences = True23 24bot = commands.Bot(command_prefix="!", intents=intents)25 26# --- 3. POWERFUL TOKEN LOADER ---27# This looks for the token even if there is a small typo in the name28def load_key(name):29 key = os.getenv(name) or os.getenv(name.lower()) or os.getenv(name + " ")30 if key:31 return key.strip()32 return None33 34DISCORD_TOKEN = load_key("MTQ5NTA1MDI1OTY3NDQzNTc0Nw.GNk4pI.HM6jrbZ9t4fkdowbWYKhcX4lp1bXnzTHCKFoqQ")35OPENROUTER_KEY = load_key("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")36 37# --- 4. AI FUNCTION ---38def get_ai_response(prompt):39 url = "https://openrouter.ai/api/v1/chat/completions"40 headers = {"Authorization": f"Bearer {OPENROUTER_KEY}", "Content-Type": "application/json"}41 data = {42 "model": "meta-llama/llama-3.1-8b-instruct:free",43 "messages": [{"role": "user", "content": prompt}]44 }45 try:46 response = requests.post(url, headers=headers, json=data)47 return response.json()['choices'][0]['message']['content']48 except:49 return "AI Error: Check OpenRouter Key."50 51# --- 5. EVENTS & COMMANDS ---52@bot.event53async def on_ready():54 print(f"โ
SUCCESS: {bot.user.name} is Online and Ready!")55 56@bot.event57async def on_message(message):58 if message.author == bot.user: return59 if not message.content.startswith(bot.command_prefix):60 async with message.channel.typing():61 await message.reply(get_ai_response(message.content))62 await bot.process_commands(message)63 64@bot.command()65async def ping(ctx):66 await ctx.send(f"๐ Pong! Latency: {round(bot.latency * 1000)}ms")67 68# --- 6. STARTUP & LOGGING ---69if __name__ == "__main__":70 print("\n===== FINAL SYSTEM CHECK =====")71 Thread(target=run_flask).start()72 73 # Diagnostic Check74 if DISCORD_TOKEN:75 print(f"โ๏ธ DISCORD_TOKEN found (Length: {len(DISCORD_TOKEN)} characters)")76 else:77 print("โ ERROR: DISCORD_TOKEN is still NULL/Empty in Hugging Face.")78 79 if OPENROUTER_KEY:80 print(f"โ๏ธ OPENROUTER_API_KEY found (Length: {len(OPENROUTER_KEY)} characters)")81 else:82 print("โ ERROR: OPENROUTER_API_KEY is NULL/Empty.")83 84 if DISCORD_TOKEN and OPENROUTER_KEY:85 print("๐ Connecting to Discord...")86 try:87 bot.run(DISCORD_TOKEN)88 except Exception as e:89 print(f"โ LOGIN FAILED: {e}")90 