Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 7 additions & 2 deletions lowchi.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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)
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
discord.py>=2.3.2
simpleeval>=0.9.13
python-dotenv>=1.0.1