From d4da58aa964fa24ffff00ac6f4000e5ddf26114c Mon Sep 17 00:00:00 2001 From: Mikko Koivunalho Date: Mon, 3 Oct 2022 23:28:44 +0200 Subject: [PATCH] Modify script to use env vars and dotenv * Use `.env` file * Use env vars PREFIX (if available, otherwise default) and TOKEN --- APIs/Discord API/discord_bot_example.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/APIs/Discord API/discord_bot_example.py b/APIs/Discord API/discord_bot_example.py index e00fc5d..02a1dec 100644 --- a/APIs/Discord API/discord_bot_example.py +++ b/APIs/Discord API/discord_bot_example.py @@ -5,10 +5,15 @@ from discord.ext import commands except ImportError: print('Please pip install discord') +try: + import os + from dotenv import load_dotenv +except ImportError: + print('Please pip install python-dotenv') -PREFIX = '!' -TOKEN = '' # Place token here +PREFIX = os.environ.get("PREFIX") if os.environ.get("PREFIX") else '!' +TOKEN = os.environ.get("TOKEN") bot = commands.Bot(command_prefix=PREFIX)