trying to handle music

This commit is contained in:
DeSqBlocki
2024-08-02 13:25:06 +02:00
parent a74e19be5a
commit 2925fb59dd
42 changed files with 3708 additions and 1 deletions
+17
View File
@@ -0,0 +1,17 @@
const { Events, ActivityType } = require('discord.js')
module.exports = {
name: Events.ClientReady,
once: true,
async execute(client) {
console.log(`Ready! Logged in as ${client.user.tag}`)
client.user.setPresence({
activities: [{
name: 'Red Dead Depression',
type: ActivityType.Streaming,
url: 'https://twitch.tv/desq_blocki'
}],
status: 'online'
})
}
}
+58
View File
@@ -0,0 +1,58 @@
const { Events } = require('discord.js')
module.exports = {
name: Events.InteractionCreate,
once: false,
async execute(interaction) {
if (interaction.isChatInputCommand()) { commandHandler(interaction) };
if (interaction.isButton()) { buttonHandler(interaction) }
if (interaction.isMentionableSelectMenu()) { selectMenuHandler(interaction)}
if (interaction.isUserSelectMenu()) { selectMenuHandler(interaction) }
}
}
async function commandHandler(interaction) {
const command = interaction.client.commands.get(interaction.commandName);
if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`);
return;
}
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
} else {
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
}
}
async function buttonHandler(interaction) {
const button = interaction.client.buttons.get(interaction.customId)
if (!button) { return console.error(`No button registered matching ${interaction.customId}.`) }
try {
await button.execute(interaction);
} catch (error) {
console.error(error);
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
} else {
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
}
}
async function selectMenuHandler(interaction) {
const selectMenu = interaction.client.selectMenus.get(interaction.customId)
if (!selectMenu) { return console.error(`No Select Menu registered matching ${interaction.customId}.`) }
try {
await selectMenu.execute(interaction);
} catch (error) {
console.error(error);
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
} else {
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
}
}
+24
View File
@@ -0,0 +1,24 @@
const { Events } = require('discord.js')
require('dotenv').config()
const { client } = require('../index')
const prefix = process.env.D_Prefix
module.exports = {
name: Events.MessageCreate,
once: false,
async execute(message) {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).trim().split(/ +/);
const cmd = args.shift().toLowerCase();
let command = client.legacyCommands.get(cmd)
if(!command) command = client.legacyCommands.get(client.aliases.get(cmd))
if(!command) return
try {
client.legacyCommands.get(command.name).execute(message, args)
} catch (error) {
console.error(error)
}
}
}
+50
View File
@@ -0,0 +1,50 @@
const { Events, ClientVoiceManager } = require("discord.js");
const { getVoiceConnection } = require('@discordjs/voice')
require('dotenv').config()
const { client } = require('../index')
const users_in_afk = new Set();
const delay = ms => new Promise(res => setTimeout(res, ms));
var connected = false;
const playlist = `https://www.youtube.com/playlist?list=PLjSh2s1ASTgsSdjCgFbpo18RAYF_dHf46`
module.exports = {
name: Events.VoiceStateUpdate,
once: false,
async execute(oldState, newState) {
const guild = client.guilds.cache.get(process.env.D_GuildID)
const afk_channel = await guild.channels.fetch(guild.afkChannelId)
const real_afk_channel = await guild.channels.fetch(process.env.D_RealTartarosID)
const user = await guild.members.fetch(newState.id)
if(user.id === process.env.D_ID) return;
// if someone enters the official AFK channel, move them to one where we can play music
if (newState.channelId === afk_channel.id) {
await delay(1000)
await user.voice.setChannel(real_afk_channel)
users_in_afk.add(newState.id)
console.log(`${users_in_afk.size} User(s) in Channel`)
if (!connected) {
connected = true;
await client.distube.voices.join(real_afk_channel)
await client.distube.play(real_afk_channel, "https://www.youtube.com/watch?v=dQw4w9WgXcQ")
const queue = client.distube.getQueue(guild)
await queue.setRepeatMode('Queue')
await queue.setVolume(40)
}
}
// if someone leaves the real AFK channel, remove them from cache but wait for rejoiners, then leave if none are here
if (oldState.channelId === real_afk_channel.id && oldState.channelId != newState.channelId) {
users_in_afk.delete(oldState.id)
}
if (users_in_afk.size === 0) {
//leave if empty
await client.distube.voices.leave(real_afk_channel)
connected = false;
}
}
}