Refactor token retrieval and error handling in main function; streamline environment variable checks for Discord token.

This commit is contained in:
2026-05-31 12:37:57 +00:00
parent ccc944ef84
commit 5fdb37f7f8
+5 -7
View File
@@ -1,8 +1,8 @@
# main.py
import discord
from discord.ext import commands
import itertools
import os
import sys
from dotenv import load_dotenv
from utils.sql_commands import initialize_database
@@ -46,12 +46,10 @@ def main():
load_dotenv()
initialize_database()
client = Client()
token = os.getenv("TOKEN")
if token is not None:
threading.Thread(target=run_web, daemon=True).start()
client.run(token)
else:
print("Token is missing.")
token = os.getenv("DISCORD_TOKEN") or os.getenv("TOKEN")
if not token:
raise SystemExit("ERROR: Discord token not found. Set DISCORD_TOKEN or TOKEN in environment.")
client.run(token)
if __name__ == "__main__":