Музыкальный бот на python (почти)

Рейтинг: 0Ответов: 0Опубликовано: 28.06.2023
import discord
from discord.ext import commands
from sever import keep_alive
import asyncio
import discord.voice_client
discord.opus.load_opus('"C:\\opus.dll"')

intents = discord.Intents.default()
intents.members = True
intents.guilds = True
intents.reactions = True
intents.messages = True

intents = discord.Intents.default().all()
client = commands.Bot(command_prefix='!', intents=intents)

@client.event
async def on_ready():
    print('Logged in as {0.user}'.format(client))

@client.event
async def on_message(message):
    print(message.content)
    await client.process_commands(message)

@client.command()
async def начинаем(ctx):
    await asyncio.sleep(5) # Задержка времени на 5 секунд
    channel = client.get_channel(1051576320187973672) # Получение объекта канала по ID
    await channel.send("Тест") # Отправка сообщения в канал

@client.command()
async def пинг(ctx):
    await ctx.send('Понг!')

@client.command()
async def мяукни(ctx):
    await ctx.send('Мяу!')

@client.command()
async def join(ctx):
    # Проверяем, есть ли автор команды в голосовом канале
    if ctx.author.voice is None or ctx.author.voice.channel is None:
        await ctx.send("Вы должны быть подключены к голосовому каналу!")
    else:
        # Проверяем, находится ли бот уже в голосовом канале
        if ctx.voice_client is not None:
            await ctx.send("Я уже нахожусь в голосовом канале")
        else:
            channel = ctx.author.voice.channel
            voice_client = await channel.connect()
            await ctx.send(f"Присоединился к каналу: {channel}")

@client.command()
async def leave(ctx):
    # Проверяем, находится ли бот в голосовом канале
    if ctx.voice_client is not None:
        await ctx.voice_client.disconnect()
        await ctx.send("Покинул голосовой канал")
    else:
        await ctx.send("Я не нахожусь в голосовом канале")

@client.command()
async def play(ctx, url):
    # Проверяем, есть ли автор команды в голосовом канале
    if ctx.author.voice is None or ctx.author.voice.channel is None:
        await ctx.send("Вы должны быть подключены к голосовому каналу!")
    else:
        # Проверяем, находится ли бот уже в голосовом канале
        if ctx.voice_client is not None and ctx.voice_client.is_playing():
            ctx.voice_client.stop()

        channel = ctx.author.voice.channel
        voice_client = await channel.connect()
        # Воспроизводим аудио из URL
        voice_client.play(discord.FFmpegPCMAudio(url))
        await ctx.send(f"Начинаю воспроизведение: {url}")

@client.command()
async def stop(ctx):
    # Проверяем, находится ли бот в голосовом канале и что проигрывается
    if ctx.voice_client is not None and ctx.voice_client.is_playing():
        ctx.voice_client.stop()
        await ctx.send("Остановлено")
    else:
        await ctx.send("В данный момент ничего не проигрывается")


keep_alive()
client.run('token')
Ошибка:
Traceback (most recent call last):
  File "main.py", line 6, in <module>
    discord.opus.load_opus('"C:\\opus.dll"')
  File "/home/runner/WhirlwindUnderstatedInstitute/venv/lib/python3.10/site-packages/discord/opus.py", line 264, in load_opus
    _lib = libopus_loader(name)
  File "/home/runner/WhirlwindUnderstatedInstitute/venv/lib/python3.10/site-packages/discord/opus.py", line 187, in libopus_loader
    lib = ctypes.cdll.LoadLibrary(name)
  File "/nix/store/hd4cc9rh83j291r5539hkf6qd8lgiikb-python3-3.10.8/lib/python3.10/ctypes/__init__.py", line 452, in LoadLibrary
    return self._dlltype(name)
  File "/nix/store/hd4cc9rh83j291r5539hkf6qd8lgiikb-python3-3.10.8/lib/python3.10/ctypes/__init__.py", line 374, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: "C:\opus.dll": cannot open shared object file: No such file or directory

путь правильный, однако ошибка осталась(

Ответы

Ответов пока нет.