Open salut-c-leo opened 2 years ago
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!" },
Are you able to reproduce that issue or send some logs after it happens? What is your stay_time value?
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"
}
what i need to do after all for that command work?
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.