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
|
.env
|
||||||
|
music/
|
@ -5,6 +5,8 @@ const YTDlpWrap = require("yt-dlp-wrap").default
|
|||||||
|
|
||||||
const ytDlp = new YTDlpWrap(`${dir}/yt-dlp`)
|
const ytDlp = new YTDlpWrap(`${dir}/yt-dlp`)
|
||||||
|
|
||||||
|
const players = {}
|
||||||
|
|
||||||
module.exports = [
|
module.exports = [
|
||||||
{
|
{
|
||||||
name: "play",
|
name: "play",
|
||||||
@ -45,8 +47,6 @@ module.exports = [
|
|||||||
connection = getVoiceConnection(ctx.guild.id)
|
connection = getVoiceConnection(ctx.guild.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(connection)
|
|
||||||
|
|
||||||
const metadata = await ytDlp.getVideoInfo(link);
|
const metadata = await ytDlp.getVideoInfo(link);
|
||||||
|
|
||||||
ctx.reply(`Playing ${metadata.title}`)
|
ctx.reply(`Playing ${metadata.title}`)
|
||||||
@ -61,8 +61,14 @@ module.exports = [
|
|||||||
'--audio-format',
|
'--audio-format',
|
||||||
'mp3'
|
'mp3'
|
||||||
]).on('close', () => {
|
]).on('close', () => {
|
||||||
|
if (players[ctx.guild.id]) {
|
||||||
|
players[ctx.guild.id].stop()
|
||||||
|
}
|
||||||
|
|
||||||
const player = createAudioPlayer()
|
const player = createAudioPlayer()
|
||||||
|
|
||||||
|
players[ctx.guild.id] = player
|
||||||
|
|
||||||
const resource = createAudioResource(`${dir}/music/${metadata.title}.mp3`)
|
const resource = createAudioResource(`${dir}/music/${metadata.title}.mp3`)
|
||||||
|
|
||||||
player.play(resource)
|
player.play(resource)
|
||||||
@ -70,5 +76,32 @@ module.exports = [
|
|||||||
connection.subscribe(player)
|
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