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
|
# main.py
|
||||||
import discord
|
import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
import itertools
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from utils.sql_commands import initialize_database
|
from utils.sql_commands import initialize_database
|
||||||
|
|
||||||
@@ -46,12 +46,10 @@ def main():
|
|||||||
load_dotenv()
|
load_dotenv()
|
||||||
initialize_database()
|
initialize_database()
|
||||||
client = Client()
|
client = Client()
|
||||||
token = os.getenv("TOKEN")
|
token = os.getenv("DISCORD_TOKEN") or os.getenv("TOKEN")
|
||||||
if token is not None:
|
if not token:
|
||||||
threading.Thread(target=run_web, daemon=True).start()
|
raise SystemExit("ERROR: Discord token not found. Set DISCORD_TOKEN or TOKEN in environment.")
|
||||||
client.run(token)
|
client.run(token)
|
||||||
else:
|
|
||||||
print("Token is missing.")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user