mrmBot-Matrix/commands/music/stop.js

27 lines
1.2 KiB
JavaScript
Raw Normal View History

import { manager, players, queues } from "../../utils/soundplayer.js";
import MusicCommand from "../../classes/musicCommand.js";
class StopCommand extends MusicCommand {
async run() {
if (!this.channel.guild) return "This command only works in servers!";
if (!this.member.voiceState.channelID) return "You need to be in a voice channel first!";
if (!this.channel.guild.members.get(this.client.user.id).voiceState.channelID) return "I'm not in a voice channel!";
2022-01-06 00:55:42 +00:00
if (!this.connection) {
await manager.leave(this.channel.guild.id);
2022-01-06 00:55:42 +00:00
return "🔊 The current voice channel session has ended.";
}
if (this.connection.host !== this.author.id && !this.member.permissions.has("manageChannels")) return "Only the current voice session host can stop the music!";
await manager.leave(this.channel.guild.id);
const connection = this.connection.player;
2021-12-13 22:09:12 +00:00
await connection.destroy();
players.delete(this.channel.guild.id);
queues.delete(this.channel.guild.id);
return "🔊 The current voice channel session has ended.";
}
static description = "Stops the music";
static aliases = ["disconnect"];
}
2021-12-13 22:09:12 +00:00
export default StopCommand;