From 6c9c601372f19057104de11c2d2eaff7b94a030b Mon Sep 17 00:00:00 2001 From: ekzyis Date: Fri, 24 Sep 2021 21:05:12 +0200 Subject: [PATCH] Implement loading token from ENV --- .env.template | 1 + .gitignore | 1 + requirements.txt | 1 + src/bot.py | 13 ++++++++++++- 4 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 .env.template diff --git a/.env.template b/.env.template new file mode 100644 index 0000000..978ac4c --- /dev/null +++ b/.env.template @@ -0,0 +1 @@ +BOT_TOKEN= \ No newline at end of file diff --git a/.gitignore b/.gitignore index 5ceb386..0330071 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ venv +.env diff --git a/requirements.txt b/requirements.txt index ba767a9..db3ff52 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,6 +11,7 @@ multidict==5.1.0 pycodestyle==2.7.0 pycparser==2.20 PyNaCl==1.4.0 +python-dotenv==0.19.0 six==1.16.0 toml==0.10.2 typing-extensions==3.10.0.2 diff --git a/src/bot.py b/src/bot.py index e791a0f..5dcf21a 100644 --- a/src/bot.py +++ b/src/bot.py @@ -1,10 +1,15 @@ import asyncio +import os import discord import youtube_dl from discord.ext import commands +from dotenv import load_dotenv + +load_dotenv() + # Suppress noise about console usage from errors youtube_dl.utils.bug_reports_message = lambda: '' @@ -134,4 +139,10 @@ async def on_ready(): print('------') bot.add_cog(Music(bot)) -bot.run('token') + +token = os.environ.get("BOT_TOKEN", None) +if not token: + print("No token fouund in BOT_TOKEN") + exit(1) + +bot.run(os.environ["BOT_TOKEN"])