Basic Discord Code added. this is our bare starting point

This commit is contained in:
Dani 2025-04-13 18:51:31 -04:00
parent 34a483d2a8
commit 7bed24a06b

50
main.py Normal file
View File

@ -0,0 +1,50 @@
import discord
import os
from dotenv import load_dotenv
from datetime import datetime
# Load environment
load_dotenv()
TOKEN = os.getenv("DISCORD_TOKEN")
if not TOKEN:
raise RuntimeError("Bot token not found in .env")
# Setup intents
intents = discord.Intents.default()
intents.message_content = True
intents.dm_messages = True
intents = intents
class Ruby(discord.Client):
def __init__(self):
super().__init__(intents=intents)
self.log_path = os.path.join("logs", "messages.log")
os.makedirs("logs", exist_ok=True)
async def on_ready(self):
print(f"[READY] Logged in as {self.user} (ID: {self.user.id})")
async def on_message(self, message: discord.Message):
if message.author.id == self.user.id:
return # ignore self
self.log_message(message)
self.train_on_message(message)
def log_message(self, message: discord.Message):
timestamp = datetime.utcnow().isoformat()
log_entry = f"{timestamp} | {message.author.name} | {message.content.strip()}\n"
with open(self.log_path, "a", encoding="utf-8") as f:
f.write(log_entry)
print(f"[LOGGED] {log_entry.strip()}")
def train_on_message(self, message: discord.Message):
print(f"[TRAIN] Simulating training on: \"{message.content.strip()}\"")
# Run Ruby
client = Ruby()
client.run(TOKEN)