0
votes

I'm trying to make my discord bot disconnect the voice channel with a command like -disconnect using Lavalink. I have tried doing it in various approaches but it never seems to work for me. I also can't find many examples online. The most recent thing i've tried is this:

  @commands.command()
  async def leave(self, ctx):
    guild_id = int(event.player.guild_id)
    await self.connect_to(guild_id, None)

Tell me if you know how to make a disconnect command. Thanks!!!

This is discord.py rewrite btw.

2

2 Answers

0
votes

To make a disconnect command is lavalink all you have to do is:

await self.connect_to(ctx.guild.id, None)
0
votes

Here's an example:

import asyncio

@client.command()
async def disconnect(ctx):
    channel = client.get_channel(channelIdHere)
    vc = await channel.connect()
    await asyncio.sleep(2) # Waits 2 seconds before leaving the vc
    await vc.disconnect()

You should check the documentation for more information.