import discord from discord.ext import commands, tasks from discord import appcommands…
- User
import discord from discord.ext import commands, tasks from discord import app_commands import aiohttp import asyncio import json from pathlib import Path from bs4 import BeautifulSoup from urllib.parse import urlparse, parse_qs import os
============================
Configuration - Fill in Your Details Below
============================
TOKEN = "MTI5MjQzNTQ1NTA5ODQ4Njg0Ng.Gq5XkY.qDAyf9NNQ7QDg8ICS250WeTClUxakWmjwwaIR0" # Replace with your bot's token as a string
NOTIFICATION_CHANNEL_ID = 1292505295028879360 # Replace with your Discord channel ID as an integer
CHECK_INTERVAL = 15 # Adjust as needed (minimum is around 15 seconds due to rate limits)
============================
End of Configuration
============================
Data persistence
BASE_DIR = Path(file).parent DATA_FILE = BASE_DIR / 'monitoring.json' if DATA_FILE.exists(): with open(DATA_FILE, 'r') as f: monitoring_data = json.load(f) else: monitoring_data = {}
def save_monitoring_data(): with open(DATA_FILE, 'w') as f: json.dump(monitoring_data, f, indent=4)
Discord Bot Setup
intents = discord.Intents.default() intents.message_content = True # Adjust as needed bot = commands.Bot(command_prefix="!", intents=intents) tree = bot.tree
@bot.event async def on_ready(): print(f"Logged in as {bot.user} (ID: {bot.user.id})") await tree.sync() print("Slash commands synced.") monitor_users.start()
@tree.command(name="monitor", description="Monitor a Roblox user joining a specific game.") @app_commands.describe(userid="Roblox User ID", gameid="Roblox Game ID (Place ID)") async def monitor(interaction: discord.Interaction, userid: str, gameid: str): if not userid.isdigit() or not gameid.isdigit(): await interaction.response.send_message("Both User ID and Game ID must be numerical.", ephemeral=True) return monitoring_data[userid] = {"gameid": gameid, "notified": False} save_monitoring_data() await interaction.response.send_message(f"✅ Started monitoring User ID {userid} for Game ID {gameid}.")
@tree.command(name="unmonitor", description="Stop monitoring a Roblox user.") @app_commands.describe(userid="Roblox User ID") async def unmonitor(interaction: discord.Interaction, userid: str): if userid in monitoring_data: del monitoring_data[userid] save_monitoring_data() await interaction.response.send_message(f"✅ Stopped monitoring User ID {userid}.") else: await interaction.response.send_message(f"❌ User ID {userid} is not being monitored.", ephemeral=True)
async def fetch_presence(session, user_id): url = "https://presence.roblox.com/v1/presence/users" headers = { "Content-Type": "application/json", "User-Agent": "Mozilla/5.0" # Some endpoints require a User-Agent header } payload = { "userIds": [int(user_id)] } try: async with session.post(url, headers=headers, json=payload) as resp: if resp.status != 200: print(f"[Error] Failed to fetch presence for User ID {user_id}. Status Code: {resp.status}") return None data = await resp.json() if "userPresences" in data and len(data["userPresences"]) > 2: presence = data["userPresences"][0] # Corrected index return presence else: print(f"[Error] No presence data found for User ID {user_id}.") return None except Exception as e: print(f"[Exception] Error fetching presence for User ID {user_id}: {e}") return None
- Assistant