pip install discord.py
import discord
from discord.ext import commands
intents = discord.Intents.default()
intents.message_content = True # Make sure the bot can read messages
bot = commands.Bot(command_prefix='!', intents=intents)
@bot.event
async def on_ready():
print(f'We have logged in as {bot.user}')
# Command to create a new voice channel
@bot.command(name='create_voice')
@commands.has_permissions(manage_channels=True)
async def create_voice(ctx, channel_name):
guild = ctx.guild
existing_channel = discord.utils.get(guild.channels, name=channel_name)
if not existing_channel:
print(f'Creating a new channel: {channel_name}')
await guild.create_voice_channel(channel_name)
await ctx.send(f'Voice channel "{channel_name}" has been created')
else:
await ctx.send(f'Channel "{channel_name}" already exists')
# Command to delete a voice channel
@bot.command(name='delete_voice')
@commands.has_permissions(manage_channels=True)
async def delete_voice(ctx, channel_name):
guild = ctx.guild
existing_channel = discord.utils.get(guild.channels, name=channel_name)
if existing_channel:
await existing_channel.delete()
await ctx.send(f'Voice channel "{channel_name}" has been deleted')
else:
await ctx.send(f'Channel "{channel_name}" does not exist')
# Command to list all voice channels
@bot.command(name='list_voice')
async def list_voice(ctx):
guild = ctx.guild
voice_channels = guild.voice_channels
response = "Voice Channels:\n"
response += "\n".join([channel.name for channel in voice_channels])
await ctx.send(response)
# Command to rename a voice channel
@bot.command(name='rename_voice')
@commands.has_permissions(manage_channels=True)
async def rename_voice(ctx, old_name, new_name):
guild = ctx.guild
existing_channel = discord.utils.get(guild.channels, name=old_name)
if existing_channel:
await existing_channel.edit(name=new_name)
await ctx.send(f'Voice channel "{old_name}" has been renamed to "{new_name}"')
else:
await ctx.send(f'Channel "{old_name}" does not exist')
# Run the bot with your token
bot.run('YOUR_DISCORD_BOT_TOKEN')
Замените YOUR_DISCORD_BOT_TOKENего фактическим токеном бота Discord.
дать достаточных прав боту
Пояснение команд:
create_voice : Создает новый голосовой канал с заданным именем.
delete_voice : удаляет существующий голосовой канал с заданным именем.
list_voice : список всех голосовых каналов на сервере.
rename_voice : переименовывает существующий голосовой канал.
Этот код предоставляет базовые функции для управления голосовыми каналами. При необходимости вы можете расширить его, включив в него дополнительные функции, такие как ограничение доступа к определенным каналам, установка ограничений на количество пользователей и многое другое.