Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Add a command to force bot to disconnect #1185

Open
salut-c-leo opened this issue Jun 20, 2022 · 4 comments
Open

Feature: Add a command to force bot to disconnect #1185

salut-c-leo opened this issue Jun 20, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@salut-c-leo
Copy link

Is your feature request related to a problem? Please describe.
Sometimes, the bot just won't leave after the timeout period is over and no music is being played. Rather than having a bot online even when no one is in the voice call, there should be a command to forcefully disconnect the bot.

Describe the solution you'd like
Like [prefix]play or [prefix]ping, [prefix]leave should disconnect the bot.

Describe alternatives you've considered
Restarting the npm service, but it's not as user-friendly and requires admin access to the console.

@salut-c-leo salut-c-leo added the enhancement New feature or request label Jun 20, 2022
@zPanic
Copy link

zPanic commented Aug 30, 2022

Hi,

Bit late, but I've coded something in that accomplishes this goal.
Create a disconnect.ts in your /commands/ folder, and put this in:

`import { Message } from "discord.js";
import { bot } from "../index";
import { i18n } from "../utils/i18n";
import { canModifyQueue } from "../utils/queue";

export default {
name: "disconnect",
aliases: ["dc"],
description: i18n.__("disconnect.description"),
execute(message: Message) {
const queue = bot.queues.get(message.guild!.id);

if (!queue) return message.reply(i18n.__("disconnect.errorNotQueue")).catch(console.error);
if (!canModifyQueue(message.member!)) return i18n.__("common.errorNotChannel");

queue.stop();

queue.textChannel.send(i18n.__mf("disconnect.result", { author: message.author })).catch(console.error);

queue.connection.destroy();

}
};`

In your /locales/en.json, add this:

"disconnect": { "description": "Stops the music and disconnects the bot", "errorNotQueue": "There is nothing playing.", "result": "🎶 Disconnected!" },

@Unnil
Copy link
Contributor

Unnil commented May 19, 2023

Are you able to reproduce that issue or send some logs after it happens?
What is your stay_time value?

@nnyj
Copy link

nnyj commented Oct 1, 2023

Updated code in case anyone needs. Thanks to @zPanic for the original code.

/commands/leave.ts:

import { ChatInputCommandInteraction, SlashCommandBuilder } from "discord.js";
import { bot } from "../index";
import { i18n } from "../utils/i18n";
import { canModifyQueue } from "../utils/queue";

export default {
  data: new SlashCommandBuilder().setName("leave").setDescription(i18n.__("leave.description")),
  async execute(interaction: ChatInputCommandInteraction) {
    const guildMember = interaction.guild!.members.cache.get(interaction.user.id);
    const queue = bot.queues.get(interaction.guild!.id);
    
    if (!queue) return interaction.reply({ content: i18n.__("stop.errorNotQueue") }).catch(console.error);

    if (!canModifyQueue(guildMember!)) return i18n.__("common.errorNotChannel");

    queue.stop();

    interaction.reply({ content: i18n.__mf("stop.result", { author: interaction.user.id }) }).catch(console.error);

    queue.connection.destroy();

    bot.queues.delete(interaction.guild!.id);
  }
}

/locales/en.json, add:

	"leave": {
		"description": "Stops the music and disconnects the bot"
	}

@NAUTH05
Copy link

NAUTH05 commented Apr 30, 2024

what i need to do after all for that command work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants