Added looping to music and fixed Boolean argument ( true | false )
This commit is contained in:
parent
8dad8dc2ea
commit
22a31762f3
@ -1,6 +1,7 @@
|
|||||||
const {createAudioPlayer, createAudioResource, joinVoiceChannel, getVoiceConnection} = require("@discordjs/voice")
|
const {createAudioPlayer, createAudioResource, joinVoiceChannel, getVoiceConnection} = require("@discordjs/voice")
|
||||||
const { Message } = require("discord.js")
|
const { Message, VoiceState } = require("discord.js")
|
||||||
const {client, dir} = require("../index")
|
const {client, dir} = require("../index")
|
||||||
|
const { AudioPlayerStatus } = require("@discordjs/voice")
|
||||||
const YTDlpWrap = require("yt-dlp-wrap").default
|
const YTDlpWrap = require("yt-dlp-wrap").default
|
||||||
|
|
||||||
const ytDlp = new YTDlpWrap(`${dir}/yt-dlp`)
|
const ytDlp = new YTDlpWrap(`${dir}/yt-dlp`)
|
||||||
@ -11,8 +12,8 @@ module.exports.commands = [
|
|||||||
{
|
{
|
||||||
name: "play",
|
name: "play",
|
||||||
description: "Joins your VC and plays music by youtube link.",
|
description: "Joins your VC and plays music by youtube link.",
|
||||||
arguments: ["link"], // If its not a OBJECT type you provide it like that lol.
|
arguments: ["link", false], // If its not a OBJECT type you provide it like that lol.
|
||||||
run: async (ctx, link) => {
|
run: async (ctx, link, loop) => {
|
||||||
// Getting the guild member to get their voice client
|
// Getting the guild member to get their voice client
|
||||||
const author = ctx.author
|
const author = ctx.author
|
||||||
const member = await ctx.guild.members.fetch(author)
|
const member = await ctx.guild.members.fetch(author)
|
||||||
@ -82,7 +83,6 @@ module.exports.commands = [
|
|||||||
|
|
||||||
players[ctx.guild.id] = player
|
players[ctx.guild.id] = player
|
||||||
|
|
||||||
// Loading music
|
|
||||||
const resource = createAudioResource(`${dir}/music/${metadata.title}.mp3`)
|
const resource = createAudioResource(`${dir}/music/${metadata.title}.mp3`)
|
||||||
|
|
||||||
// Playing the music with the player
|
// Playing the music with the player
|
||||||
@ -90,6 +90,17 @@ module.exports.commands = [
|
|||||||
|
|
||||||
// Subscribing the connection to the player
|
// Subscribing the connection to the player
|
||||||
connection.subscribe(player)
|
connection.subscribe(player)
|
||||||
|
|
||||||
|
if (loop) {
|
||||||
|
player.on("stateChange", (oldState, newState) => {
|
||||||
|
if (newState.status == AudioPlayerStatus.Idle && players[ctx.guild.id] != undefined) {
|
||||||
|
// Gotta create a new resource every time
|
||||||
|
const resource = createAudioResource(`${dir}/music/${metadata.title}.mp3`)
|
||||||
|
|
||||||
|
player.play(resource)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -104,6 +115,8 @@ module.exports.commands = [
|
|||||||
}
|
}
|
||||||
|
|
||||||
players[ctx.guild.id].stop()
|
players[ctx.guild.id].stop()
|
||||||
|
|
||||||
|
players[ctx.guild.id] = undefined
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
5
index.js
5
index.js
@ -117,6 +117,7 @@ client.on("messageCreate", async (message) => {
|
|||||||
|
|
||||||
// Parsing
|
// Parsing
|
||||||
args.forEach((arg, index) => {
|
args.forEach((arg, index) => {
|
||||||
|
|
||||||
if (arg.startsWith("<@")) {
|
if (arg.startsWith("<@")) {
|
||||||
// User, lets get the id
|
// User, lets get the id
|
||||||
const id = arg.slice(2, arg.length - 1)
|
const id = arg.slice(2, arg.length - 1)
|
||||||
@ -137,8 +138,8 @@ client.on("messageCreate", async (message) => {
|
|||||||
}
|
}
|
||||||
} else if (Number(arg)) {
|
} else if (Number(arg)) {
|
||||||
args[index] = Number(arg)
|
args[index] = Number(arg)
|
||||||
} else if (Boolean(arg)) {
|
} else if (arg == "true" || arg == "false") {
|
||||||
args[index] = Boolean(arg)
|
args[index] = arg == "true" // This is awful man.
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks if the type is wrong
|
// Checks if the type is wrong
|
||||||
|
Loading…
x
Reference in New Issue
Block a user