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 { Message } = require("discord.js")
|
||||
const { Message, VoiceState } = require("discord.js")
|
||||
const {client, dir} = require("../index")
|
||||
const { AudioPlayerStatus } = require("@discordjs/voice")
|
||||
const YTDlpWrap = require("yt-dlp-wrap").default
|
||||
|
||||
const ytDlp = new YTDlpWrap(`${dir}/yt-dlp`)
|
||||
@ -11,8 +12,8 @@ module.exports.commands = [
|
||||
{
|
||||
name: "play",
|
||||
description: "Joins your VC and plays music by youtube link.",
|
||||
arguments: ["link"], // If its not a OBJECT type you provide it like that lol.
|
||||
run: async (ctx, link) => {
|
||||
arguments: ["link", false], // If its not a OBJECT type you provide it like that lol.
|
||||
run: async (ctx, link, loop) => {
|
||||
// Getting the guild member to get their voice client
|
||||
const author = ctx.author
|
||||
const member = await ctx.guild.members.fetch(author)
|
||||
@ -24,7 +25,7 @@ module.exports.commands = [
|
||||
if (member.voice) {
|
||||
channel = member.voice.channel
|
||||
}
|
||||
|
||||
|
||||
// Returns if the user is not in vc or the bot is already in one
|
||||
if (!channel) {
|
||||
return ctx.reply("You are not in a VC right now.")
|
||||
@ -81,8 +82,7 @@ module.exports.commands = [
|
||||
const player = createAudioPlayer()
|
||||
|
||||
players[ctx.guild.id] = player
|
||||
|
||||
// Loading music
|
||||
|
||||
const resource = createAudioResource(`${dir}/music/${metadata.title}.mp3`)
|
||||
|
||||
// Playing the music with the player
|
||||
@ -90,6 +90,17 @@ module.exports.commands = [
|
||||
|
||||
// Subscribing the connection to the 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] = undefined
|
||||
}
|
||||
},
|
||||
{
|
||||
|
7
index.js
7
index.js
@ -117,6 +117,7 @@ client.on("messageCreate", async (message) => {
|
||||
|
||||
// Parsing
|
||||
args.forEach((arg, index) => {
|
||||
|
||||
if (arg.startsWith("<@")) {
|
||||
// User, lets get the id
|
||||
const id = arg.slice(2, arg.length - 1)
|
||||
@ -137,10 +138,10 @@ client.on("messageCreate", async (message) => {
|
||||
}
|
||||
} else if (Number(arg)) {
|
||||
args[index] = Number(arg)
|
||||
} else if (Boolean(arg)) {
|
||||
args[index] = Boolean(arg)
|
||||
} else if (arg == "true" || arg == "false") {
|
||||
args[index] = arg == "true" // This is awful man.
|
||||
}
|
||||
|
||||
|
||||
// Checks if the type is wrong
|
||||
if (typeof args[index] != typeof realCommand.arguments[index] && !(args[index] instanceof realCommand.arguments[index])) {
|
||||
wrongArg = true // So it cant continue
|
||||
|
Loading…
x
Reference in New Issue
Block a user