From 0aafe950f762a7460a412fb0fe0fc2ee17ccd0cb Mon Sep 17 00:00:00 2001 From: Essem Date: Tue, 9 Nov 2021 10:49:17 -0600 Subject: [PATCH] Added seek --- commands/music/seek.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 commands/music/seek.js diff --git a/commands/music/seek.js b/commands/music/seek.js new file mode 100644 index 0000000..489ac31 --- /dev/null +++ b/commands/music/seek.js @@ -0,0 +1,24 @@ +import { Rest } from "lavacord"; +import MusicCommand from "../../classes/musicCommand.js"; + +class SeekCommand extends MusicCommand { + async run() { + if (!this.message.channel.guild) return "This command only works in servers!"; + if (!this.message.member.voiceState.channelID) return "You need to be in a voice channel first!"; + if (!this.message.channel.guild.members.get(this.client.user.id).voiceState.channelID) return "I'm not in a voice channel!"; + if (this.connection.host !== this.message.author.id) return "Only the current voice session host can seek the music!"; + const player = this.connection.player; + const track = await Rest.decode(player.node, player.track); + if (!track.isSeekable) return "This track isn't seekable!"; + const seconds = parseInt(this.args[0]); + if (isNaN(seconds) || (seconds * 1000) > track.length || (seconds * 1000) < 0) return "That's not a valid position!"; + player.seek(seconds * 1000); + return `🔊 Seeked track to ${seconds} seconds.`; + } + + static description = "Seeks to a different position in the music"; + static aliases = ["pos"]; + static arguments = ["[seconds]"]; +} + +export default SeekCommand; \ No newline at end of file