Skip to content

Instantly share code, notes, and snippets.

@NNKTV28
Created March 3, 2023 11:26
Show Gist options
  • Save NNKTV28/580a2e31681b9b4bfa42ab82ad006b77 to your computer and use it in GitHub Desktop.
Save NNKTV28/580a2e31681b9b4bfa42ab82ad006b77 to your computer and use it in GitHub Desktop.
import itertools
import discord
import lavalink
from discord.ext import commands
class disconnect(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.command(description="?dc, ?DC", aliases=['dc', 'DC'])
async def disconnect(self, ctx):
"Disconnects the player from the voice channel and clears its queue."
player = self.bot.lavalink.player_manager.get(ctx.guild.id)
if not ctx.voice_client:
# We can't disconnect, if we're not connected.
embed = discord.Embed(
title= "Disconnect",
description=f"📡| Not connected",
color=discord.Color.dark_blue(),
timestamp=ctx.message.created_at
)
embed.set_author(
name=self.bot.user.name,
icon_url=self.bot.user.display_avatar.url
)
embed.set_footer(text="Made by NNKtv28")
await ctx.send(embed=embed)
if not ctx.author.voice or (player.is_connected and ctx.author.voice.channel.id != int(player.channel_id)):
# Abuse prevention. Users not in voice channels, or not in the same voice channel as the bot
# may not disconnect the bot.
embed = discord.Embed(
title= "Disconnect",
description=f"📡| You\'re not in my voicechannel!",
color=discord.Color.dark_blue(),
timestamp=ctx.message.created_at
)
embed.set_author(
name=self.bot.user.name,
icon_url=self.bot.user.display_avatar.url
)
embed.set_footer(text="Made by NNKtv28")
await ctx.send(embed=embed)
# Clear the queue to ensure old tracks don't start playing
# when someone else queues something.
player.queue.clear()
# Stop the current track so Lavalink consumes less resources.
await player.stop()
# Disconnect from the voice channel.
await ctx.voice_client.disconnect(force=True)
embed = discord.Embed(
title= 'Disconnected',
description=f' | Disconnected from {player.channel_id}.',
color=discord.Color.dark_blue(),
timestamp=ctx.message.created_at
)
embed.set_author(
name=self.bot.user.name,
icon_url=self.bot.user.display_avatar.url
)
embed.set_footer(text="Made by NNKtv28")
await ctx.send(embed=embed)
async def setup(bot):
await bot.add_cog(disconnect(bot))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment