More comments and changed README.md

This commit is contained in:
Entarno54 2025-05-24 02:12:40 +07:00
parent 22a31762f3
commit 5d6103a0aa
3 changed files with 42 additions and 29 deletions

7
.gitignore vendored
View File

@ -103,7 +103,6 @@ dist
# vuepress v2.x temp and cache directory # vuepress v2.x temp and cache directory
.temp .temp
.cache
# Docusaurus cache and generated files # Docusaurus cache and generated files
.docusaurus .docusaurus
@ -129,7 +128,5 @@ dist
.yarn/build-state.yml .yarn/build-state.yml
.yarn/install-state.gz .yarn/install-state.gz
.pnp.* .pnp.*
music/
.idea
.env
music/

View File

@ -1,4 +1,4 @@
# Squod Administrator / Fun bot. # Squog Administrator / Fun bot.
Features: Features:
- Prefix command parser for discord.js - Prefix command parser for discord.js
@ -7,10 +7,11 @@ Features:
Every single part of code is commented to be understandable for others Every single part of code is commented to be understandable for others
How to use: How to use:
- ```git clone https://git.squog.ru/entar/SquogAdmin.git``` - Clone the repository: ```git clone https://git.squog.ru/entar/SquogAdmin.git```
- ```cd SquogAdmin``` - Change the directory into it: ```cd SquogAdmin```
- ```npm install``` - Install dependencies: ```npm install```
- ```npm run exec``` - Create a .env file where you provide the token: ```TOKEN = xxxx```
- Run the bot: ```npm run exec```
###### Code is F2U, keep it OpenSource ###### Code is F2U, keep it OpenSource
###### Crediting me is optional but i'd prefer to be there. ###### Crediting me is optional but i'd prefer to be there.

View File

@ -1,6 +1,5 @@
const {createAudioPlayer, createAudioResource, joinVoiceChannel, getVoiceConnection} = require("@discordjs/voice") const {createAudioPlayer, createAudioResource, joinVoiceChannel, getVoiceConnection} = require("@discordjs/voice")
const { Message, VoiceState } = require("discord.js") const {dir} = require("../index")
const {client, dir} = require("../index")
const { AudioPlayerStatus } = require("@discordjs/voice") const { AudioPlayerStatus } = require("@discordjs/voice")
const YTDlpWrap = require("yt-dlp-wrap").default const YTDlpWrap = require("yt-dlp-wrap").default
@ -12,16 +11,16 @@ module.exports.commands = [
{ {
name: "play", name: "play",
description: "Joins your VC and plays music by youtube link.", description: "Joins your VC and plays music by youtube link.",
arguments: ["link", false], // If its not a OBJECT type you provide it like that lol. arguments: ["link", false], // If it's not an OBJECT type, you provide it like that lol.
run: async (ctx, link, loop) => { run: async (ctx, link, loop) => {
// Getting the guild member to get their voice client // Getting the guild member to get their voice client
const author = ctx.author const author = ctx.author
const member = await ctx.guild.members.fetch(author) const member = await ctx.guild.members.fetch(author)
// Initiating the channel variable (undefined) // Initiating the channel variable (undefined)
var channel let channel;
// Checking if member is in a voice chat // Checking if the member is in a voice chat
if (member.voice) { if (member.voice) {
channel = member.voice.channel channel = member.voice.channel
} }
@ -29,22 +28,22 @@ module.exports.commands = [
// Returns if the user is not in vc or the bot is already in one // Returns if the user is not in vc or the bot is already in one
if (!channel) { if (!channel) {
return ctx.reply("You are not in a VC right now.") return ctx.reply("You are not in a VC right now.")
} else if (ctx.guild.members.me.voice.channel && ctx.guild.members.me.voice.channel.id != channel.id) { } else if (ctx.guild.members.me.voice.channel && ctx.guild.members.me.voice.channel.id !== channel.id) {
return ctx.reply("Already in a vc.") return ctx.reply("Already in a vc.")
} }
var connection let connection;
// Checking if the bot is already in the vc // Checking if the bot is already in the vc
if (!ctx.guild.members.me.voice.channel) { if (!ctx.guild.members.me.voice.channel) {
// Connecting to voice channel // Connecting to the voice channel
connection = joinVoiceChannel({ connection = joinVoiceChannel({
channelId: channel.id, channelId: channel.id, // Jetbrains is very angry over this for no reason?
guildId: channel.guild.id, guildId: channel.guild.id, // Or maybe this, it shows String instead of Snowflake.
adapterCreator: channel.guild.voiceAdapterCreator, adapterCreator: channel.guild.voiceAdapterCreator,
}) })
} else { } else {
// Getting a existing connection // Getting an existing connection
connection = getVoiceConnection(ctx.guild.id) connection = getVoiceConnection(ctx.guild.id)
} }
@ -56,7 +55,7 @@ module.exports.commands = [
await reply.edit(`Downloading ${metadata.title}`) await reply.edit(`Downloading ${metadata.title}`)
// Running yt-dlp (downloading music) // Running yt-dlp (downloading music)
const music = ytDlp.exec([ ytDlp.exec([
// Arguments to run yt-dlp with // Arguments to run yt-dlp with
link, link,
'-f', '-f',
@ -69,18 +68,22 @@ module.exports.commands = [
]).on('close', () => { ]).on('close', () => {
reply.edit(`Playing ${metadata.title}`) reply.edit(`Playing ${metadata.title}`)
// Stopping old audioplayer // Stopping old audio player
if (players[ctx.guild.id]) { if (players[ctx.guild.id]) {
players[ctx.guild.id].stop() 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)) { // Checking if the bot is still in the VC and if it's the same VC.
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.") return reply.edit("Not in a VC anymore, not playing.")
} }
// Connecting audio player // Connecting audio player
const player = createAudioPlayer() const player = createAudioPlayer()
// Setting the global player to this
players[ctx.guild.id] = player players[ctx.guild.id] = player
const resource = createAudioResource(`${dir}/music/${metadata.title}.mp3`) const resource = createAudioResource(`${dir}/music/${metadata.title}.mp3`)
@ -91,12 +94,14 @@ module.exports.commands = [
// Subscribing the connection to the player // Subscribing the connection to the player
connection.subscribe(player) connection.subscribe(player)
// Make it play again and again if it's looping
if (loop) { if (loop) {
player.on("stateChange", (oldState, newState) => { player.on("stateChange", (oldState, newState) => {
if (newState.status == AudioPlayerStatus.Idle && players[ctx.guild.id] != undefined) { if (newState.status === AudioPlayerStatus.Idle && players[ctx.guild.id] !== undefined) {
// Gotta create a new resource every time // We have to create a new resource every time
const resource = createAudioResource(`${dir}/music/${metadata.title}.mp3`) const resource = createAudioResource(`${dir}/music/${metadata.title}.mp3`)
// Playing the music with the player
player.play(resource) player.play(resource)
} }
}) })
@ -110,27 +115,37 @@ module.exports.commands = [
run: (ctx) => { run: (ctx) => {
const voice = ctx.guild.members.me.voice const voice = ctx.guild.members.me.voice
// Checking if bot is in a voice channel
if (!voice || !players[ctx.guild.id]) { if (!voice || !players[ctx.guild.id]) {
return ctx.reply("Not in a voice channel.") return ctx.reply("Not in a voice channel.")
} }
// Stopping the player
players[ctx.guild.id].stop() players[ctx.guild.id].stop()
// Removing the player (needed on line 100 check)
players[ctx.guild.id] = undefined players[ctx.guild.id] = undefined
} }
}, },
{ {
name: "leave", name: "leave",
description: "Leave the channel", description: "Leave the channel",
run: (ctx) => { run: async (ctx) => {
const voice = ctx.guild.members.me.voice const voice = ctx.guild.members.me.voice
// Checking if bot is in a voice channel
if (!voice || !players[ctx.guild.id]) { if (!voice || !players[ctx.guild.id]) {
return ctx.reply("Not in a voice channel.") return ctx.reply("Not in a voice channel.")
} }
// Stopping the player
players[ctx.guild.id].stop() players[ctx.guild.id].stop()
voice.disconnect() // Removing the player (needed on line 100 check)
players[ctx.guild.id] = undefined
// Disconnecting, obviously.
await voice.disconnect()
} }
} }
] ]