diff --git a/commands/base.js b/commands/base.js index 33f7c8a..0319a3f 100644 --- a/commands/base.js +++ b/commands/base.js @@ -1,7 +1,7 @@ const {client, commands} = require("../index") const { EmbedBuilder, Message, Colors } = require("discord.js") -module.exports = [ +module.exports.commands = [ { name: "ping", run: (ctx, args) => { diff --git a/commands/voice.js b/commands/voice.js index c4295aa..07a91fa 100644 --- a/commands/voice.js +++ b/commands/voice.js @@ -7,7 +7,7 @@ const ytDlp = new YTDlpWrap(`${dir}/yt-dlp`) const players = {} -module.exports = [ +module.exports.commands = [ { name: "play", description: "Hello tested for now", @@ -73,6 +73,10 @@ module.exports = [ players[ctx.guild.id].stop() } + if (!ctx.guild.members.me.voice || (ctx.guild.members.me.voice && !ctx.guild.members.me.voice.channel) || (ctx.guild.members.me.voice && ctx.guild.members.me.voice.channel && ctx.guild.members.me.voice.channel.id != channel.id)) { + return reply.edit("Not in a VC anymore, not playing.") + } + // Connecting audio player const player = createAudioPlayer() @@ -116,4 +120,6 @@ module.exports = [ voice.disconnect() } } -] \ No newline at end of file +] + +module.exports.players = players // For use in events/voice.js \ No newline at end of file diff --git a/events/voice.js b/events/voice.js new file mode 100644 index 0000000..82cd8da --- /dev/null +++ b/events/voice.js @@ -0,0 +1,23 @@ +const {client, dir} = require("../index") +const {Events} = require("discord.js") +const {createAudioPlayer, createAudioResource, joinVoiceChannel, getVoiceConnection} = require("@discordjs/voice") +const {players} = require("../commands/voice") + +client.on(Events.VoiceStateUpdate, (oldState, newState) => { + if (newState.channel) { + return // Return if still connected + } + const connection = getVoiceConnection(oldState.guild.id) + + if (!connection || (connection && oldState.guild.members.me.voice.channelId != oldState.channel.id)) { + return // Return if bot is not connected or connected to a diff vc. + } + + const channel = oldState.channel + if (channel.members > 1) { + return // Return if theres still someone in vc + } + + + connection.disconnect() // Disconnect if noone is in vc +}) \ No newline at end of file diff --git a/index.js b/index.js index f44da21..4a4cb10 100644 --- a/index.js +++ b/index.js @@ -43,7 +43,7 @@ fs.readdir(`${__dirname}/commands`, (err, files) => { return } - const commandList = require(`${__dirname}/commands/${file}`) + const commandList = require(`${__dirname}/commands/${file}`).commands commands.push(commandList) }) @@ -158,6 +158,26 @@ client.on("messageCreate", async (message) => { } ) +/* + +Command preset: + +module.exports.commands = [ //module.exports.commands exports ONLY COMMANDLISTS. + { + name: "name", // !name + + description: "description", // (opt) + + run: (ctx, link, member, num) => {}, // run function + + hide: false, // hide from !help or not + + arguments: ["link", GuildMember, 1] // argument types, + } +] + +*/ + // After getting the command list we can export it module.exports.commands = commands