3
votes

I want to make my discord bot to connect to the voice channel I am when I type !join. i have tried to do it with the following code but i got this error: bot: BotInstance of 'Bot' has no 'voice_client_int' memberpylint(no-member)

i found that my code is not compatible with the rewrite discord version.

@bot.command(pass_context = True)
async def join(ctx):
        channel = ctx.message.author.voice.voice_channel
        await bot.join_voice_channel(channel)
@bot.command(pass_context = True)
async def leave(ctx):
        server = ctx.message.server
        voice_client = bot.voice_client_int(server)
        await voice_client.disconnect()

can someone help me?

1

1 Answers

8
votes

As stated in the migrating page, in the rewrite version, the voice connection is now a method of the VoiceChannel model. The pass_context is also deprecated as context is now always passed.

It now would look like this:

@bot.command()
async def join(ctx):
    channel = ctx.author.voice.channel
    await channel.connect()
@bot.command()
async def leave(ctx):
    await ctx.voice_client.disconnect()

Of course this oversimplified version lacks error handling.