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 # Replace "nixos" with "fagOS" (preserving case of the first letter), but exclude URLs starting with http(s):// new_content = re.sub( r'(https?://\S+)|(\bnixos\b)', lambda m: m.group(1) if m.group(1) else ('FagOS' if m.group(2)[0].isupper() else 'fagOS'), message.content, flags=re.IGNORECASE ) # Only proceed if the content was actually modified if new_content != message.content: # Get or create a webhook for impersonation webhooks = await message.channel.webhooks() webhook = next((w for w in webhooks if w.name == 'FagOSWebhook'), None) if webhook is None: webhook = await message.channel.create_webhook(name='FagOSWebhook') await message.delete() # Delete the original # Send the modified message via webhook with original user's username and avatar await webhook.send( content=new_content, username=message.author.display_name, avatar_url=message.author.display_avatar.url ) # 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'))