Fix playerButtons + generatePlayer
This commit is contained in:
@@ -7,8 +7,17 @@ const playerButtons = require(appDir + '/utilsPlayer/buttons.js')
|
||||
module.exports = {
|
||||
name: Events.InteractionCreate,
|
||||
async execute(interaction) {
|
||||
if (!interaction.isAutocomplete() && !interaction.isChatInputCommand() && !interaction.isButton()) return console.error(`Interaction ${interaction.commandName} is not a command.`)
|
||||
//if (!interaction.isAutocomplete() && !interaction.isChatInputCommand() && !interaction.isButton()) return console.error(`Interaction ${interaction.commandName} is not a command.`)
|
||||
|
||||
if (interaction.isChatInputCommand()) {
|
||||
let command = interaction.client.commands.get(interaction.commandName)
|
||||
if (!command) return console.error(`No command matching ${interaction.commandName} was found.`)
|
||||
|
||||
console.log(`\u001b[1;33m Command '${interaction.commandName}' launched by ${interaction.user.tag}`)
|
||||
|
||||
try { await command.execute(interaction) }
|
||||
catch (error) { console.error(`Error executing ${interaction.commandName}:`, error) }
|
||||
}
|
||||
else if (interaction.isAutocomplete()) {
|
||||
let autoCompleteRun = interaction.client.commands.get(interaction.commandName)
|
||||
if (!autoCompleteRun) return console.error(`No autoCompleteRun matching ${interaction.commandName} was found.`)
|
||||
@@ -18,17 +27,6 @@ module.exports = {
|
||||
try { await autoCompleteRun.autocompleteRun(interaction) }
|
||||
catch (error) { console.error(`Error autocompleting ${interaction.commandName}:`, error) }
|
||||
}
|
||||
|
||||
else if (interaction.isChatInputCommand()) {
|
||||
let command = interaction.client.commands.get(interaction.commandName)
|
||||
if (!command) return console.error(`No command matching ${interaction.commandName} was found.`)
|
||||
|
||||
console.log(`\u001b[1;33m Command '${interaction.commandName}' launched by ${interaction.user.tag}`)
|
||||
|
||||
try { await command.execute(interaction) }
|
||||
catch (error) { console.error(`Error executing ${interaction.commandName}:`, error) }
|
||||
}
|
||||
|
||||
else if (interaction.isButton()) {
|
||||
let button = interaction.client.buttons.get(interaction.customId)
|
||||
if (!button) return console.error(`No button id matching ${interaction.customId} was found.`)
|
||||
|
||||
@@ -1,23 +1,13 @@
|
||||
const { Events } = require('discord.js')
|
||||
const { useMasterPlayer, useQueue } = require('discord-player')
|
||||
require('dotenv').config()
|
||||
|
||||
const appDir = require('path').dirname(require.main.filename)
|
||||
const replay = require(appDir + '/utilsPlayer/replay.js')
|
||||
const disco = require(appDir + '/utilsPlayer/disco.js')
|
||||
|
||||
//const { DataTypes } = require("sequelize")
|
||||
//const sequelize = require('../utils/initSequelize.js')
|
||||
|
||||
const appDir = require('path').dirname(require.main.filename)
|
||||
const generatePlayer = require(appDir + '/utilsPlayer/generate.js')
|
||||
const getUptime = require(appDir + '/utils/getUptime.js')
|
||||
|
||||
const dance = async function (bot_id, channel, embed, components) {
|
||||
let messages = await channel.messages.fetch()
|
||||
let botMessage = messages.find(msg => msg.author.id === bot_id)
|
||||
if (!botMessage || (!components && botMessage.components.length > 0)) {
|
||||
await channel.bulkDelete(messages)
|
||||
return await channel.send({ embeds: [embed] })
|
||||
} else await botMessage.edit({ embeds: [embed], components })
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
name: Events.ClientReady,
|
||||
once: true,
|
||||
@@ -25,46 +15,7 @@ module.exports = {
|
||||
console.log(`\u001b[1;35m Ready! Logged in as ${client.user.tag}`)
|
||||
|
||||
// Check if a music session was active before the bot was restarted
|
||||
if (process.env.DISCORD_MUSIC_CURRENT_TRACK) {
|
||||
let textChannel = client.channels.cache.get(process.env.DISCORD_MUSIC_TEXTCHANNEL_ID)
|
||||
let voiceChannel = client.channels.cache.get(process.env.DISCORD_MUSIC_VOICECHANNEL_ID)
|
||||
|
||||
let player = useMasterPlayer()
|
||||
let queue = player.nodes.create(textChannel.guild, {
|
||||
metadata: {
|
||||
channel: textChannel,
|
||||
client: textChannel.guild.members.me,
|
||||
requestedBy: client.user
|
||||
},
|
||||
selfDeaf: true,
|
||||
volume: 20,
|
||||
leaveOnEmpty: true,
|
||||
leaveOnEmptyCooldown: 300000,
|
||||
leaveOnEnd: true,
|
||||
leaveOnEndCooldown: 300000,
|
||||
skipOnNoStream: true
|
||||
})
|
||||
|
||||
try { if (!queue.connection) await queue.connect(voiceChannel) }
|
||||
catch (error) { console.error(error); await textChannel.send(`Y'a eu un problème, <@223831938346123275> ! (${error.message})`) }
|
||||
|
||||
let result = await player.search(process.env.DISCORD_MUSIC_CURRENT_TRACK, { requestedBy: client.user })
|
||||
if (!result.hasTracks()) await textChannel.send(`Aucune musique trouvée pour **${query}** !`)
|
||||
let track = result.tracks[0]
|
||||
|
||||
let entry = queue.tasksQueue.acquire()
|
||||
await entry.getTask()
|
||||
queue.addTrack(track)
|
||||
|
||||
let progress = process.env.DISCORD_MUSIC_CURRENT_PROGRESS
|
||||
|
||||
try {
|
||||
await queue.node.play()
|
||||
queue.node.seek(progress)
|
||||
await textChannel.send(`Relancement de la musique suite à mon redémarrage...`)
|
||||
} catch (error) { console.error(error); await textChannel.send(`Y'a eu un problème, <@223831938346123275> ! (${error.message})`) }
|
||||
finally { queue.tasksQueue.release() }
|
||||
}
|
||||
if (process.env.DISCORD_MUSIC_CURRENT_TRACK) await replay(client)
|
||||
|
||||
//try {
|
||||
// sequelize.authenticate()
|
||||
@@ -72,38 +23,8 @@ module.exports = {
|
||||
//} catch (error) { console.error('Unable to connect to the database:', error) }
|
||||
|
||||
var interval = setInterval(async () => {
|
||||
//client.guilds.cache.each(async guild => {
|
||||
//const Data = sequelize.define(guild.id, {
|
||||
// playerChannelId: DataTypes.STRING
|
||||
//})
|
||||
//await sequelize.sync({ force: true })
|
||||
|
||||
//if (!Data.playerChannelId) {
|
||||
// clearInterval(interval)
|
||||
// return console.log(`\u001b[1;31m Aucun channel inscrit dans la base, veuillez utiliser la commande \`/setchannel\` !`)
|
||||
//}
|
||||
//let channel = client.channels.cache.get(Data.playerChannelId)
|
||||
|
||||
let guild = client.guilds.cache.get(process.env.DISCORD_GUILD_ID)
|
||||
let channel = client.channels.cache.get(process.env.DISCORD_PLAYERCHANNEL_ID)
|
||||
if (!channel) {
|
||||
clearInterval(interval)
|
||||
return console.log(`\u001b[1;31m Error: Aucun channel trouvé avec l'id \`${process.env.DISCORD_PLAYERCHANNEL_ID}\`, veuillez utiliser la commande \`/setchannel\` !`)
|
||||
}
|
||||
|
||||
// Keep track of the music progress if the bot reboots
|
||||
let queue = useQueue(guild.id)
|
||||
if (queue) if (queue.isPlaying()) writeEnv('DISCORD_MUSIC_CURRENT_PROGRESS', queue.node.playbackTime)
|
||||
|
||||
let { embed, components } = await generatePlayer(guild)
|
||||
if (components) {
|
||||
embed.setFooter({ text: `Uptime: ${getUptime(client.uptime)} / ${embed.data.footer.text}` })
|
||||
await dance(client.user.id, channel, embed, components)
|
||||
} else {
|
||||
embed.setFooter({ text: `Uptime: ${getUptime(client.uptime)}` })
|
||||
await dance(client.user.id, channel, embed)
|
||||
}
|
||||
//})
|
||||
}, 4000)
|
||||
let state = await disco(client)
|
||||
if (state === 'clear') clearInterval(interval)
|
||||
}, 2000)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user