Better command exporting, made bot leave if left in VC alone
This commit is contained in:
parent
5f27195b6b
commit
7d520be06f
@ -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) => {
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
]
|
||||
]
|
||||
|
||||
module.exports.players = players // For use in events/voice.js
|
23
events/voice.js
Normal file
23
events/voice.js
Normal file
@ -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
|
||||
})
|
22
index.js
22
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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user