discord/pwsBot/resource/credentials.py
2024-04-23 17:18:24 -07:00

20 lines
547 B
Python

import json
import sys
TOKEN = 'token'
def get_token(file_path):
try:
with open(file_path, 'r') as file:
data = json.load(file)
if TOKEN in data:
return data[TOKEN]
else:
print("Bot token file missing " + str(TOKEN) + " field. See README.")
except FileNotFoundError:
print("No bot token file. See README.")
except json.JSONDecodeError:
print("Invalid JSON format for bot token file. See README.")
sys.exit(1)