diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c49bd7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env diff --git a/README.md b/README.md index 1816042..2ec1693 100644 --- a/README.md +++ b/README.md @@ -21,3 +21,14 @@ A fun little Discord bot built with `discord.py` that can greet users and answer ```bash git clone https://github.com/your-username/discord-math-bot.git cd discord-math-bot + +2. Create ``.env`` file that stores your discord bot token as: + ```env + DISCORD_TOKEN=your-discord-bot-token-here + +> [!WARNING] +> NOTE: Never commit your ``.env`` file to version control, as it will expose your bot token. It will automatically be ignored via ``.gitignore``. + +3. Install dependencies by running: + ```bash + pip install -r requirements.txt diff --git a/lowchi.py b/lowchi.py index 0b1957e..ec315d0 100644 --- a/lowchi.py +++ b/lowchi.py @@ -1,5 +1,8 @@ import discord +import os from discord.ext import commands +from simpleeval import simple_eval +from dotenv import load_dotenv bot = discord.Bot() # Create a bot instance @@ -21,7 +24,7 @@ async def math(ctx, *, question: str): expression = question.lower().replace('what is', '').strip() # Evaluate the expression try: - result = eval(expression) + result = simple_eval(expression) # Respond to the user await ctx.send(f"Hi {ctx.author.name}, the answer is {result}! Do you want to know why?") # Wait for user response @@ -41,4 +44,6 @@ async def math(ctx, *, question: str): await ctx.send("Sorry, I couldn't understand the expression. Please provide a valid math question.") # Run the bot with your Discord bot token -bot.run('DISCORD.TOKEN') +load_dotenv() # Load from .env +token = os.getenv("DISCORD_TOKEN") +bot.run(token) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..55e21fc --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +discord.py>=2.3.2 +simpleeval>=0.9.13 +python-dotenv>=1.0.1