Files
bot.py
requirements.txt
Code
2 115
bot.py
import discord
from discord.ext import commands
import os
from dotenv import load_dotenv
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
if not TOKEN:
raise ValueError("DISCORD_TOKEN not found in .env file")
intents = discord.Intents.default()
intents.voice_states = True
intents.guilds = True
intents.message_content = True
bot = commands.Bot(command_prefix='!', intents=intents, help_command=None)
@bot.event
async def on_ready():
print(f'Logged in as {bot.user} (ID: {bot.user.id})')
print(f'Invite URL: https://discord.com/api/oauth2/authorize?client_id={bot.user.id}&permissions=3145728&scope=bot%20applications.commands')
print('------')
@bot.command(name='vc')
async def voice_channels(ctx):
"""Show all voice channels with member counts."""
guild = ctx.guild
if not guild:
await ctx.send("This command can only be used in a server.")
return
voice_channels = guild.voice_channels
if not voice_channels:
await ctx.send("This server has no voice channels.")
return
embed = discord.Embed(
title=f"Voice Channels in {guild.name}",
color=discord.Color.blue()
)
total_members = 0
for channel in voice_channels:
member_count = len(channel.members)
total_members += member_count
if member_count > 0:
member_names = '\n'.join(
[m.display_name for m in channel.members[:10]]
)
if len(channel.members) > 10:
member_names += f'\n... and {len(channel.members) - 10} more'
embed.add_field(
name=f"🔊 {channel.name} ({member_count})",
value=member_names or 'No one',
inline=False
)
embed.set_footer(text=f"Total: {total_members} member(s) in voice channels")
await ctx.send(embed=embed)
@bot.command(name='vctotal')
async def vc_total(ctx):
"""Show total number of people in voice channels."""
guild = ctx.guild
if not guild:
await ctx.send("This command can only be used in a server.")
return
total = sum(len(vc.members) for vc in guild.voice_channels)
await ctx.send(f"🔊 **{total}** member(s) are currently in voice channels.")
@bot.command(name='vcin')
async def vc_in(ctx, *, channel_name: str):
"""Check a specific voice channel by name."""
guild = ctx.guild
if not guild:
await ctx.send("This command can only be used in a server.")
return
channel = discord.utils.get(guild.voice_channels, name=channel_name)
if not channel:
await ctx.send(f"Could not find a voice channel named **{channel_name}**.")
return
members = channel.members
if not members:
await ctx.send(f"🔇 **{channel.name}** is empty.")
return
member_list = '\n'.join([f"• {m.display_name}" for m in members])
await ctx.send(
f"🔊 **{channel.name}** — {len(members)} member(s)\n{member_list}"
)
@bot.event
async def on_command_error(ctx, error):
if isinstance(error, commands.MissingRequiredArgument):
await ctx.send(f"Usage: `!{ctx.command.name} {ctx.command.signature}`")
elif isinstance(error, commands.CommandNotFound):
pass
else:
print(f"Error in {ctx.command}: {error}")
if __name__ == '__main__':
bot.run(TOKEN)