'python discord music bot AttributeError: 'Music' object has no attribute '_get_voice_client_key'

Currently writing discord bot, it has some error when I type command to play music

Trying to fix this problem but it still not work...it keep getting error like this:

An error occurred: Command raised an exception: AttributeError: 'Music' object has no attribute '_get_voice_client_key'

this is my class and play command :

    class Music(commands.Cog):

    def __init__(self, bot: commands.Bot):
        self.bot = bot
        self.voice_states = {}

    def get_voice_state(self, ctx: commands.Context):
        state = self.voice_states.get(ctx.guild.id)
        if not state:
            state = VoiceState(self.bot, ctx)
            self.voice_states[ctx.guild.id] = state

        return state

    async def cog_before_invoke(self, ctx: commands.Context):
        ctx.voice_state = self.get_voice_state(ctx)

    async def cog_command_error(self, ctx: commands.Context, error: commands.CommandError):
        await ctx.send('An error occurred: {}'.format(str(error)))


    @commands.command(name='play')
    async def _play(self, ctx: commands.Context, *,url):
        vc= await VoiceChannel.connect(self)
        vc.play(discord.FFmpegPCMAudio(executable="C:\\ffmpeg\\bin\\ffmpeg.exe", source="mp3.mp3"))
        FFMPEG_OPTIONS = {'before_options':'-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 'option': 'vn'}
        voice = get(guild=ctx.guild)
 

        if not voice.is_playing():
            with YoutubeDL(Music.YDL_OPTIONS) as ydl:
                info = ydl.extract_info(url, download=False)
            URL = info['formats'][0]['url']
            voice.play(FFmpegPCMAudio(URL, **FFMPEG_OPTIONS))
            voice.is_playing()
        else:
            await ctx.send("Already playing song")
            return

bot.add_cog(Music(bot))

thank you for help!!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source