A problem with sound reproduction in the voice channel

52 Views Asked by At

I have code that can work without errors and the bot can join the voice channel, but when it joins it doesn't do anything. And he doesn't send anything either. My ffmpeg.exe file is in the same directory as main.py. I tried to do it other ways but had as same problem.

main.py:

import discord
from discord.ext import tasks, commands
import yt_dlp

bot = discord.Bot()

@bot.slash_command(name="play", help="Play music")
async def play(ctx, url):
    if ctx.voice_client is None:
        if ctx.author.voice:
            channel = ctx.author.voice.channel
            vc = await channel.connect()

            await play_music(vc, url)
        else:
            await ctx.respond("You are not connected to a voice channel.")
    else:
        await ctx.respond("I'm already connected to a voice channel.")

async def play_music(voice_client, url):
    ffmpeg_path = "ffmpeg.exe"
    voice_client.volume = 0.5
    voice_client.play(discord.FFmpegPCMAudio(url, executable=ffmpeg_path), after=lambda e: print('Player error: %s' % e) if e else None)

bot.run(TOKEN)
0

There are 0 best solutions below