Added music folder to gitignore and added stop and leave commands
This commit is contained in:
parent
811465e3ad
commit
6b4603f1f7
1
.gitignore
vendored
1
.gitignore
vendored
@ -132,3 +132,4 @@ dist
|
||||
|
||||
|
||||
.env
|
||||
music/
|
@ -5,6 +5,8 @@ const YTDlpWrap = require("yt-dlp-wrap").default
|
||||
|
||||
const ytDlp = new YTDlpWrap(`${dir}/yt-dlp`)
|
||||
|
||||
const players = {}
|
||||
|
||||
module.exports = [
|
||||
{
|
||||
name: "play",
|
||||
@ -45,8 +47,6 @@ module.exports = [
|
||||
connection = getVoiceConnection(ctx.guild.id)
|
||||
}
|
||||
|
||||
console.log(connection)
|
||||
|
||||
const metadata = await ytDlp.getVideoInfo(link);
|
||||
|
||||
ctx.reply(`Playing ${metadata.title}`)
|
||||
@ -61,8 +61,14 @@ module.exports = [
|
||||
'--audio-format',
|
||||
'mp3'
|
||||
]).on('close', () => {
|
||||
if (players[ctx.guild.id]) {
|
||||
players[ctx.guild.id].stop()
|
||||
}
|
||||
|
||||
const player = createAudioPlayer()
|
||||
|
||||
players[ctx.guild.id] = player
|
||||
|
||||
const resource = createAudioResource(`${dir}/music/${metadata.title}.mp3`)
|
||||
|
||||
player.play(resource)
|
||||
@ -70,5 +76,32 @@ module.exports = [
|
||||
connection.subscribe(player)
|
||||
})
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "stop",
|
||||
description: "Stop music",
|
||||
run: (ctx) => {
|
||||
const voice = ctx.guild.members.me.voice
|
||||
|
||||
if (!voice || !players[ctx.guild.id]) {
|
||||
return ctx.reply("Not in a voice channel.")
|
||||
}
|
||||
|
||||
players[ctx.guild.id].stop()
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "leave",
|
||||
description: "Leave the channel",
|
||||
run: (ctx) => {
|
||||
const voice = ctx.guild.members.me.voice
|
||||
|
||||
if (!voice || !players[ctx.guild.id]) {
|
||||
return ctx.reply("Not in a voice channel.")
|
||||
}
|
||||
players[ctx.guild.id].stop()
|
||||
|
||||
voice.disconnect()
|
||||
}
|
||||
}
|
||||
]
|
Loading…
x
Reference in New Issue
Block a user