e4677b7564
bot.run() was crashing with PrivilegedIntentsRequired because intents.message_content=True needs the toggle enabled in the Discord developer portal. Mirror SREBOT's intent config: message_content=False, reactions+messages on. TSSBOT can opt into the privileged intent later if/when it needs message content. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
55 lines
1.4 KiB
Python
55 lines
1.4 KiB
Python
#!/usr/bin/env python3
|
|
"""Entry point for TSSBOT. Connects to Discord and idles until commands land."""
|
|
import logging
|
|
import os
|
|
import signal
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
# Make TSSBOT root and BOTS/SHARED importable.
|
|
_HERE = Path(__file__).resolve().parent
|
|
sys.path.insert(0, str(_HERE))
|
|
sys.path.insert(0, str(_HERE.parent / "SHARED"))
|
|
|
|
import discord
|
|
from discord.ext import commands
|
|
from dotenv import load_dotenv
|
|
|
|
load_dotenv(dotenv_path=_HERE / ".env")
|
|
|
|
logging.basicConfig(
|
|
level=logging.INFO,
|
|
format="[%(asctime)s] [%(levelname)s] [tssbot] %(message)s",
|
|
datefmt="%Y-%m-%d %H:%M:%S",
|
|
)
|
|
log = logging.getLogger("tssbot")
|
|
|
|
|
|
def _handle_signal(signum, _frame):
|
|
log.info(f"received signal {signum}, exiting")
|
|
sys.exit(0)
|
|
|
|
|
|
TOKEN = os.environ.get("DISCORD_KEY", "").strip()
|
|
|
|
intents = discord.Intents.default()
|
|
intents.message_content = False
|
|
intents.reactions = True
|
|
intents.messages = True
|
|
bot = commands.Bot(command_prefix="!", intents=intents)
|
|
|
|
|
|
@bot.event
|
|
async def on_ready():
|
|
log.info(f"logged in as {bot.user} (id={bot.user.id if bot.user else '?'})")
|
|
log.info(f"connected to {len(bot.guilds)} guild(s)")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
signal.signal(signal.SIGTERM, _handle_signal)
|
|
signal.signal(signal.SIGINT, _handle_signal)
|
|
if not TOKEN:
|
|
log.error("DISCORD_KEY not set in TSSBOT/.env — aborting")
|
|
sys.exit(1)
|
|
bot.run(TOKEN, log_handler=None)
|