Files
fagos/bot.py
Zastian Pretorius 3971a76d02 first commit
2025-08-28 00:21:50 +01:00

40 lines
1.3 KiB
Python

import discord
from discord.ext import commands
import re
import os
# Set up intents explicitly
intents = discord.Intents.default()
intents.message_content = True # Enable message content access
# Set up the bot
bot = commands.Bot(command_prefix='!', intents=intents)
# Event: Bot is ready and connected to Discord
@bot.event
async def on_ready():
print(f'Logged in as {bot.user.name}')
# Event: Triggered when a message is sent in a channel the bot can see
@bot.event
async def on_message(message):
# Ignore messages sent by the bot itself to prevent loops
if message.author == bot.user:
return
# Check if the message contains "nixos" (case-insensitive, as a whole word)
if re.search(r'\bnixos\b', message.content, re.IGNORECASE):
# Replace "nixos" with "fagos" (preserving case of the first letter)
new_content = re.sub(
r'\b(nixos)\b',
lambda m: 'Fagos' if m.group(1)[0].isupper() else 'fagos',
message.content,
flags=re.IGNORECASE
)
# Send the modified message
await message.channel.send(f'{new_content}')
# Allow other commands to process (if any)
await bot.process_commands(message)
# Run the bot using the token from the environment variable
bot.run(os.getenv('FAGOS_TOKEN'))