refactor: streamlining of main function

Update utilizing walrus operators, only importing the sub-namespace we
need from os & sys.
This commit is contained in:
Price Hiller 2023-01-27 13:07:54 -06:00
parent 074666786f
commit a35755592c

View File

@ -1,16 +1,16 @@
import os
import discord
from os import environ
from sys import stderr
# main runtime function
def main():
try:
disToken = os.environ['DISCORD_TOKEN'] # grabs the discord token from the environment variable, if not there, exit
except:
print("ERROR: unable to find discord token in environment variables!")
if disToken := environ.get('DISCORD_TOKEN'):
print(f"Received discord token: {disToken}")
# Call into main action here, basically launch the bot via import to a lower module
else:
print("Unable to access DISCORD_TOKEN in environment!", file=stderr)
exit(1)
print("hello world")
main()