2021-11-09 16:49:17 +00:00
|
|
|
import MusicCommand from "../../classes/musicCommand.js";
|
|
|
|
|
|
|
|
class SeekCommand extends MusicCommand {
|
|
|
|
async run() {
|
2022-09-01 01:00:34 +00:00
|
|
|
this.success = false;
|
2022-09-24 03:25:16 +00:00
|
|
|
if (!this.guild) return "This command only works in servers!";
|
2022-09-27 19:46:07 +00:00
|
|
|
if (!this.member.voiceState) return "You need to be in a voice channel first!";
|
2022-10-24 01:27:32 +00:00
|
|
|
if (!this.guild.voiceStates.has(this.client.user.id)) return "I'm not in a voice channel!";
|
2022-10-12 03:36:45 +00:00
|
|
|
if (!this.connection) return "I haven't completely connected yet!";
|
2022-03-31 05:42:03 +00:00
|
|
|
if (this.connection.host !== this.author.id) return "Only the current voice session host can seek the music!";
|
2021-11-09 16:49:17 +00:00
|
|
|
const player = this.connection.player;
|
2022-06-14 05:38:01 +00:00
|
|
|
const track = await player.node.rest.decode(player.track);
|
2021-11-09 16:49:17 +00:00
|
|
|
if (!track.isSeekable) return "This track isn't seekable!";
|
2022-08-25 15:36:12 +00:00
|
|
|
const pos = this.options.position ?? this.args[0];
|
|
|
|
let seconds;
|
2022-09-01 01:00:34 +00:00
|
|
|
if (typeof pos === "string" && pos.includes(":")) {
|
2022-08-25 15:36:12 +00:00
|
|
|
seconds = +(pos.split(":").reduce((acc, time) => (60 * acc) + +time));
|
|
|
|
} else {
|
|
|
|
seconds = parseFloat(pos);
|
|
|
|
}
|
2021-11-09 16:49:17 +00:00
|
|
|
if (isNaN(seconds) || (seconds * 1000) > track.length || (seconds * 1000) < 0) return "That's not a valid position!";
|
2022-06-14 05:38:01 +00:00
|
|
|
player.seekTo(seconds * 1000);
|
2022-09-01 01:00:34 +00:00
|
|
|
this.success = true;
|
2021-11-09 23:42:18 +00:00
|
|
|
return `🔊 Seeked track to ${seconds} second(s).`;
|
2021-11-09 16:49:17 +00:00
|
|
|
}
|
|
|
|
|
2022-04-05 03:05:28 +00:00
|
|
|
static flags = [{
|
|
|
|
name: "position",
|
2022-08-25 15:36:12 +00:00
|
|
|
type: 3,
|
2022-04-05 03:05:28 +00:00
|
|
|
description: "Seek to this position",
|
2022-08-25 15:36:12 +00:00
|
|
|
required: true
|
2022-04-05 03:05:28 +00:00
|
|
|
}];
|
2021-11-09 16:49:17 +00:00
|
|
|
static description = "Seeks to a different position in the music";
|
|
|
|
static aliases = ["pos"];
|
|
|
|
static arguments = ["[seconds]"];
|
|
|
|
}
|
|
|
|
|
2021-12-13 22:09:12 +00:00
|
|
|
export default SeekCommand;
|