Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import discord
- from discord.ext import commands
- import aiohttp
- import asyncio
- # Only Edit this! ---
- TOKEN = "BOT_TOKEN" # Bot Token here!
- OWNER_ID = OWNER_ID # Enter your Discord user Id here!
- # Only Edit this! ---
- intents = discord.Intents.default()
- intents.message_content = True
- intents.voice_states = True
- bot = commands.Bot(command_prefix='!', intents=intents)
- STREAM_URL = "https://stream.laut.fm/infiloocast"
- BOT_CHANNEL_ID: int | None = None # Track ID instead of the object to avoid stale cache data
- CURRENT_SONG = "InfilooCast 24/7"
- IS_LIVE = False
- IS_247 = False # Track if the bot is in 24/7 permanent mode
- async def update_voice_status():
- """Fetches the fresh voice channel object and updates its status string"""
- global BOT_CHANNEL_ID
- if BOT_CHANNEL_ID:
- # Fetching fresh channel reference directly from the current bot cache
- live_channel = bot.get_channel(BOT_CHANNEL_ID)
- if live_channel and isinstance(live_channel, discord.VoiceChannel):
- try:
- await live_channel.edit(status=f"πΆ {CURRENT_SONG}"[:100])
- except Exception as e:
- print(f"Could not update voice status: {e}")
- async def update_song_title():
- """Fetches current song from Laut.fm API"""
- global CURRENT_SONG
- try:
- async with aiohttp.ClientSession() as session:
- async with session.get("https://api.laut.fm/station/infiloocast/current_song") as resp:
- if resp.status == 200:
- data = await resp.json()
- artist = data["artist"]["name"]
- title = data["title"]
- CURRENT_SONG = f"{artist} - {title}"[:50]
- else:
- CURRENT_SONG = "InfilooCast Live"
- except:
- CURRENT_SONG = "InfilooCast 24/7"
- async def update_presence_loop():
- """Updates RPC and Voice Status every 25s with new song"""
- while True:
- await update_song_title()
- # Update Rich Presence
- if IS_LIVE:
- await bot.change_presence(
- activity=discord.Streaming(
- name="π΄ Infiloo is now Live |",
- url="https://www.guns.lol/infiloo",
- details=f"πΆ {CURRENT_SONG}"
- )
- )
- else:
- await bot.change_presence(
- activity=discord.Streaming(
- name="InfilooCast 24/7 π΅",
- url="https://www.twitch.tv/discord",
- details=f"πΆ {CURRENT_SONG}"
- )
- )
- await update_voice_status()
- await asyncio.sleep(25)
- async def ensure_bot_connected_and_playing(channel: discord.VoiceChannel):
- """Joins channel, starts stream, and pushes voice status"""
- vc = channel.guild.voice_client
- if vc:
- if vc.channel != channel:
- await vc.move_to(channel)
- else:
- vc = await channel.connect()
- if not vc.is_playing():
- vc.play(discord.FFmpegPCMAudio(STREAM_URL, executable='ffmpeg'))
- await update_voice_status()
- @bot.event
- async def on_ready():
- print(f'{bot.user} online! π΅ Auto-Join + Live RPC!')
- await update_song_title()
- await bot.change_presence(
- activity=discord.Streaming(
- name="InfilooCast 24/7 π΅",
- url="https://www.twitch.tv/discord",
- details=f"πΆ {CURRENT_SONG}"
- )
- )
- bot.loop.create_task(update_presence_loop())
- for guild in bot.guilds:
- bot_member = guild.get_member(bot.user.id)
- if bot_member:
- try:
- await bot_member.edit(deafen=True)
- except:
- pass
- @bot.command()
- async def join(ctx):
- global BOT_CHANNEL_ID, IS_247
- if ctx.author.id != OWNER_ID:
- await ctx.send("β **Only the Bot-Owner has the permission to use !join**")
- return
- if not ctx.author.voice or not ctx.author.voice.channel:
- await ctx.send("β **You have to be in a Voice channel!**")
- return
- target_channel = ctx.author.voice.channel
- BOT_CHANNEL_ID = target_channel.id
- IS_247 = False
- if len(target_channel.members) > 0:
- await ensure_bot_connected_and_playing(target_channel)
- await ctx.send(f"π΅ **InfilooCast is running in {target_channel.mention}!**")
- else:
- await ctx.send(f"β **Channel set: {target_channel.mention}**\n"
- f"**Bot automatically joins if someone else joins!**")
- @bot.command()
- @commands.has_permissions(administrator=True)
- async def join24(ctx):
- global BOT_CHANNEL_ID, IS_247
- if not ctx.author.voice or not ctx.author.voice.channel:
- await ctx.send("β **You have to be in a Voice channel!**")
- return
- target_channel = ctx.author.voice.channel
- BOT_CHANNEL_ID = target_channel.id
- IS_247 = True
- await ensure_bot_connected_and_playing(target_channel)
- await ctx.send(f"βΎοΈ **InfilooCast is now running 24/7 in {target_channel.mention}!**\n*The bot will not disconnect if left alone.*")
- @join24.error
- async def join24_error(ctx, error):
- if isinstance(error, commands.MissingPermissions):
- await ctx.send("β **Only server Administrators can use !join24**")
- @bot.command()
- async def stop(ctx):
- global BOT_CHANNEL_ID, IS_247
- if ctx.author.id != OWNER_ID and not ctx.author.guild_permissions.administrator:
- await ctx.send("β **Only the Bot-Owner or an Admin can use !stop**")
- return
- if BOT_CHANNEL_ID:
- try:
- live_channel = bot.get_channel(BOT_CHANNEL_ID)
- if live_channel:
- await live_channel.edit(status=None)
- except:
- pass
- BOT_CHANNEL_ID = None
- IS_247 = False
- if ctx.voice_client:
- await ctx.voice_client.disconnect()
- await ctx.send("βΉοΈ **Auto-Join/24-7 mode stopped. Bot disconnected.**")
- @bot.command()
- async def status(ctx):
- if ctx.author.id != OWNER_ID and not ctx.author.guild_permissions.administrator:
- return
- status = "β **ACTIVE**" if BOT_CHANNEL_ID else "β **STOPPED**"
- live_channel = bot.get_channel(BOT_CHANNEL_ID) if BOT_CHANNEL_ID else None
- channel_info = live_channel.mention if live_channel else "No Channel"
- live_status = "π΄ **LIVE**" if IS_LIVE else "π£ **24/7**"
- mode_info = "βΎοΈ 24/7 Stay" if IS_247 else "π€ Auto-Join/Leave"
- await ctx.send(f"**Bot-Status:** {status}\n**Goal:** {channel_info}\n**Mode:** {live_status} ({mode_info})\n**Song:** πΆ {CURRENT_SONG}")
- @bot.command()
- async def live(ctx):
- global IS_LIVE
- if ctx.author.id != OWNER_ID:
- await ctx.send("β **Only the Bot-Owner can use !live**")
- return
- IS_LIVE = True
- await update_song_title()
- await bot.change_presence(
- activity=discord.Streaming(
- name="π΄ Infiloo is now Live |",
- url="https://www.guns.lol/infiloo",
- details=f"πΆ {CURRENT_SONG}"
- )
- )
- await update_voice_status()
- await ctx.send("π΄ **RPC switched to LIVE mode!**")
- @bot.command()
- async def offline(ctx):
- global IS_LIVE
- if ctx.author.id != OWNER_ID:
- await ctx.send("β **Only the Bot-Owner can use !offline**")
- return
- IS_LIVE = False
- await bot.change_presence(
- activity=discord.Streaming(
- name="InfilooCast 24/7 π΅",
- url="https://www.twitch.tv/discord",
- details=f"πΆ {CURRENT_SONG}"
- )
- )
- await update_voice_status()
- await ctx.send("π£ **RPC switched back to 24/7 mode!**")
- @bot.event
- async def on_voice_state_update(member, before, after):
- global BOT_CHANNEL_ID, IS_247
- if BOT_CHANNEL_ID is None:
- return
- vc = member.guild.voice_client
- live_channel = bot.get_channel(BOT_CHANNEL_ID)
- if not IS_247 and after.channel == live_channel and member.id != bot.user.id:
- await ensure_bot_connected_and_playing(live_channel)
- if not IS_247 and vc and vc.channel == live_channel:
- humans = [m for m in live_channel.members if not m.bot]
- if len(humans) == 0:
- try:
- await live_channel.edit(status=None)
- except:
- pass
- await vc.disconnect()
- bot.run(TOKEN)
Advertisement