in server answering ban

This commit is contained in:
Creat0r
2025-11-30 15:30:01 +01:00
parent 133e14be3b
commit 3d815ac453
2 changed files with 20 additions and 16 deletions

3
.gitignore vendored
View File

@ -2,4 +2,5 @@
token.yaml token.yaml
ollama-api.yaml ollama-api.yaml
__pycache__/* __pycache__/*
bin/__pycache__/* bin/__pycache__/*
tokent.yaml

View File

@ -1,9 +1,12 @@
import discord import discord
from discord.ext import commands from discord.ext import commands
import skills as skills import skills
import asyncio import asyncio
import yaml import yaml
# -----------------------------
# Token laden
# -----------------------------
with open("token.yaml", "r") as yamlfile: with open("token.yaml", "r") as yamlfile:
data = yaml.load(yamlfile, Loader=yaml.FullLoader) data = yaml.load(yamlfile, Loader=yaml.FullLoader)
@ -12,46 +15,46 @@ with open("token.yaml", "r") as yamlfile:
# ----------------------------- # -----------------------------
intents = discord.Intents.default() intents = discord.Intents.default()
intents.message_content = True intents.message_content = True
intents.guilds = True
intents.dm_messages = True
bot = commands.Bot(command_prefix="!", intents=intents) bot = commands.Bot(command_prefix="!", intents=intents)
# ----------------------------- # -----------------------------
# Events # Events
# ----------------------------- # -----------------------------
@bot.event @bot.event
async def on_ready(): async def on_ready():
await bot.tree.sync() # Slash Commands registrieren
print(f"Logged in as {bot.user}") print(f"Logged in as {bot.user}")
@bot.event @bot.event
async def on_message(message): async def on_message(message):
# Bot ignoriert eigene Nachrichten
if message.author == bot.user: if message.author == bot.user:
return return
try: try:
# Wenn Nachricht ein Command ist, nur Commands verarbeiten # Commands verarbeiten
if message.content.startswith(bot.command_prefix): if message.content.startswith(bot.command_prefix):
await bot.process_commands(message) await bot.process_commands(message)
return return
# Alles andere → skills.process_text # -----------------------------
loop = asyncio.get_running_loop() # DM Nachrichten
result = await loop.run_in_executor(None, skills.process_text, message.content) # -----------------------------
if isinstance(message.channel, discord.DMChannel):
# Längere Ausgaben als Code-Block loop = asyncio.get_running_loop()
if len(result) > 1900: result = await loop.run_in_executor(None, skills.process_text, message.content)
await message.channel.send(f"```\n{result}\n```") if len(result) > 1900:
else: await message.channel.send(f"```\n{result}\n```")
await message.channel.send(result) else:
await message.channel.send(result)
except Exception as e: except Exception as e:
print(f"Error in on_message: {e}") print(f"Error in on_message: {e}")
await message.channel.send(f"⚠️ Fehler: {e}") await message.channel.send(f"⚠️ Fehler: {e}")
# ----------------------------- # -----------------------------
# Bot starten # Bot starten
# ----------------------------- # -----------------------------
bot.run(data[0]['token']) bot.run(data[0]['token'])