Refactor token retrieval and error handling in main function; streamline environment variable checks for Discord token.
This commit is contained in:
@@ -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__":
|
||||
|
||||
Reference in New Issue
Block a user