diff --git a/Main.py b/Main.py index 8cdc905..cca408b 100644 --- a/Main.py +++ b/Main.py @@ -9,11 +9,9 @@ import re # Show the path we expect to load # Explicitly find the .env file in the same directory as the script - env_path = Path(__file__).resolve().parent / ".env" print(f"Looking for .env at: {env_path}") - # Load the env file load_dotenv(dotenv_path=env_path) @@ -24,7 +22,16 @@ print(f"Loaded token Succesfully") if token is None: raise RuntimeError(".env file not loaded or DISCORD_TOKEN not set.") -# --- Load bad words from file into a set --- +### Declare generic and global variables here ### +handler = logging.FileHandler(filename='discord.log', encoding='utf-8', mode='w') +intents = discord.Intents.default() +intents.message_content = True +intents.members = True +bot = commands.Bot(command_prefix='!', intents=intents) + +# --- Load bad words from file into a set when the bot starts, +# --- this makes the file accessed only once each time the bot runs, +# --- as oppsoed to checking the txt file every time a discord message comes though --- with open("bad_words.txt", "r", encoding="utf-8") as f: BAD_WORDS = {line.strip().lower() for line in f if line.strip()} @@ -32,16 +39,6 @@ with open("bad_words.txt", "r", encoding="utf-8") as f: # \b = word boundary, (?i) = case-insensitive bad_words_pattern = re.compile(r"\b(" + "|".join(map(re.escape, BAD_WORDS)) + r")\b", re.IGNORECASE) - -token = os.getenv("DISCORD_TOKEN") - -handler = logging.FileHandler(filename='discord.log', encoding='utf-8', mode='w') -intents = discord.Intents.default() -intents.message_content = True -intents.members = True - -bot = commands.Bot(command_prefix='!', intents=intents) - @bot.event async def on_ready(): print(f"{bot.user.name} is ready") @@ -55,7 +52,9 @@ async def on_ready(): @bot.event async def on_member_join(member): - await member.send(f"Welcome to the server {member.name}") + await member.send(f"Welcome to the server {member.name}!") + # Should we give new members some points just for joining so they can start off with something? - Joshypoo + # we should also add users to the DB on member join, becasue we will get to a point where the bot isn't constantly restarting #Responding to cuss words @bot.event