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
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ python --version

- Install the required dependencies:
```bash
pip install discord
pip install discord python-dotenv
```
(`python-dotenv` is optional, it only lets you keep your token in a `.env` file instead of a system environment variable.)

## Discord Application Deployment

Expand Down Expand Up @@ -98,6 +99,12 @@ pip install discord

8. You may use the Generated URL to invite your bot into your servers.

9. Go to the `Bot` section and scroll down to `Privileged Gateway Intents`, then turn **all three** of them on:
`Presence Intent`, `Server Members Intent` and `Message Content Intent`.

EconBot reads normal chat messages to catch its `!` commands, and Discord keeps that behind a switch you have to flip yourself.
If you skip this step the bot will crash on startup with `PrivilegedIntentsRequired`.

---

<strong>Token Setup & Environment Variable Setup</strong>
Expand All @@ -122,6 +129,14 @@ pip install discord

[Linux (Ubuntu)](https://www.youtube.com/watch?v=Y6_7xaxkPik)

_Alternatively_, if you installed `python-dotenv`, you can create a file named `.env` next to `main.py` containing:

```
econtoken=YOUR TOKEN HERE
```

`.env` is already in `.gitignore`, so your token won't be committed by accident.

_Alternatively_ you can just directly paste the bot token into the code; however, this is __not recommended__.

- To do this, go to the file `main.py` and on the last line you should see
Expand Down
16 changes: 15 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Libraries
import discord
import os
import sys

try:
from dotenv import load_dotenv
load_dotenv() # Loads a local .env file if one exists, system env vars still take priority.
except ImportError:
pass # python-dotenv is optional, a system environment variable works just as well.

import singletons
import constants
Expand Down Expand Up @@ -208,4 +215,11 @@ async def InvokeEcon(message : discord.Message) -> None:
await message.reply(embed=embed)


singletons.client.run(os.getenv("econtoken"))
token = os.getenv("econtoken")

if not token:
singletons.print_colored("[ NO TOKEN FOUND ! ]", "red")
print("Set an environment variable named 'econtoken', or put econtoken=<your token> in a .env file next to main.py.")
sys.exit(1)

singletons.client.run(token)
5 changes: 3 additions & 2 deletions saveload/saveload.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ async def SaveUserDict() -> None:
print(f"Error: {err}")

def LoadUserDict() -> bool:
if not os.path.exists(save_path):
os.mknod(save_path)
if not os.path.exists(save_path) or os.path.getsize(save_path) == 0:
singletons.user_dict = {} # Fresh install, nothing saved yet. SaveUserDict creates the file later.
return True
with open(save_path,'rb') as file:
singletons.user_dict = pickle.load(file=file)
return True
Expand Down
2 changes: 0 additions & 2 deletions singletons.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ async def Save(self):

print_colored("--- Client disconnected ---", "red")

exit(0)

async def close(self):
# Perform cleanup before closing
await self.async_cleanup()
Expand Down