bot.py import discord from discord.ext import commands, tasks from discord import…
- User
bot.py
import discord from discord.ext import commands, tasks from discord import app_commands import aiohttp import asyncio import json import os from bs4 import BeautifulSoup import re
============================
Configuration - Fill in Your Details Below
============================
Discord Bot Token
TOKEN = "MTI5MjQzNTQ1NTA5ODQ4Njg0Ng.GrBVz-.2R3qdlTOWVfWaWvMdWRPPFmGdgcWVV6Gw88ajY"
Notification Channel ID
NOTIFICATION_CHANNEL_ID = 1292505295028879360
Check Interval in Seconds
CHECK_INTERVAL = 3
============================
End of Configuration
============================
File to store monitoring data
DATA_FILE = 'monitoring.json'
Initialize monitoring data
if os.path.exists(DATA_FILE): with open(DATA_FILE, 'r') as f: try: monitoring_data = json.load(f) except json.JSONDecodeError: monitoring_data = {} else: monitoring_data = {}
def save_monitoring_data(): """ Save the current monitoring data to a JSON file. """ with open(DATA_FILE, 'w') as f: json.dump(monitoring_data, f, indent=4)
Intents
intents = discord.Intents.default() intents.message_content = True # Ensure this is enabled in the Discord Developer Portal for your bot
Initialize Bot
bot = commands.Bot(command_prefix="!", intents=intents)
Tree for Slash Commands
tree = bot.tree
@bot.event async def on_ready(): """ Event handler called when the bot is ready. """ print(f"Logged in as {bot.user} (ID: {bot.user.id})") print("------") # Sync global commands (this might take up to an hour to propagate if not using guild-specific commands) await tree.sync() print("Commands synced globally.") monitor_users.start() # Start the background monitoring task
@tree.command(name="monitor", description="Monitor a Roblox user joining a specific game.") @app_commands.describe( userid="The Roblox User ID to monitor (numeric ID).", gameid="The Roblox Game ID to monitor (numeric ID)." ) async def monitor(interaction: discord.Interaction, userid: str, gameid: str): """ Start monitoring a Roblox user for when they join a specific game. """ if not userid.isdigit() or not gameid.isdigit(): await interaction.response.send_message("❌ Both
useridandgameidmust be numeric IDs.", ephemeral=True) returncodemonitoring_data[userid] = { "gameid": gameid, "notified": False # To prevent multiple notifications for the same event } save_monitoring_data() await interaction.response.send_message( f"✅ Started monitoring Roblox User ID **{userid}** for Game ID **{gameid}**." ) - Assistant