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
============================
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)
Discord Bot Setup
intents = discord.Intents.all() bot = commands.Bot(command_prefix="!", intents=intents) tree = bot.tree
@bot.event async def on_ready(): print(f"Logged in as {bot.user}") await tree.sync() 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") async def monitor(interaction: discord.Interaction, userid: str, gameid: str): 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_current_game_from_profile(session, user_id): url = f"https://www.roblox.com/users/{user_id}/profile" async with session.get(url) as resp: if resp.status != 200: return None text = await resp.text() soup = BeautifulSoup(text, 'html.parser') status = soup.find('a', class_='avatar-status') if status and 'href' in status.attrs: href = status['href'] from urllib.parse import urlparse, parse_qs query = parse_qs(urlparse(href).query) if 'PlaceId' in query: return query['PlaceId'][0] return None
async def fetch_username(session, user_id): url = f"" async with session.get(url) as resp: if resp.status != 200: return "Unknown User" data = await resp.json() return data.get('name', 'Unknown User')
- Assistant