From 884e1acf7d3982e66f28dc2cd68e74325f704c6c Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Mon, 28 Mar 2022 14:25:23 -0400 Subject: Added more buttons to control command --- AudioBackend.js | 7 +++---- bot.js | 4 +--- commands/control.js | 32 +++++++++++++++++++++++++++++--- commands/help.js | 2 +- deploy-command.js | 10 +++++----- 5 files changed, 39 insertions(+), 16 deletions(-) diff --git a/AudioBackend.js b/AudioBackend.js index ec4167d..dbc239a 100644 --- a/AudioBackend.js +++ b/AudioBackend.js @@ -24,10 +24,9 @@ import { MessageEmbed } from 'discord.js' import config from './config.json' assert {type: 'json'} import fs from 'fs' -const player = createAudioPlayer(); +export const player = createAudioPlayer(); export let audio; let fileData; -let txtFile = true; export function voiceInit(bot) { @@ -48,12 +47,12 @@ export function voiceInit(bot) { player.on('idle', () => { console.log("Music has finished playing, shuffling music...") - playAudio(); + playAudio(bot); }) playAudio(bot); connection.subscribe(player); - }) + }).catch(e => { console.error("The voice channel does not exist!\\n(Have you looked at your configuration?)") }) } export function playAudio(bot) { diff --git a/bot.js b/bot.js index 8aef7c3..957f40a 100644 --- a/bot.js +++ b/bot.js @@ -24,8 +24,6 @@ import fs from "fs" import config from './config.json' assert {type: 'json'} export const bot = new Client({intents: ['GUILDS', 'GUILD_MESSAGES', 'GUILD_VOICE_STATES']}); -let fileData; -let txtFile = true; bot.login(config.token); @@ -71,7 +69,7 @@ bot.once('ready', () => { // Send bots' status to channel const readyEmbed = new MessageEmbed() - .setAuthor({name:bot.user.username, iconURL:bot.user.avatarURL()}) + .setAuthor({ name: bot.user.username, iconURL: bot.user.avatarURL()} ) .setDescription('Starting bot...') .setColor('#0066ff') diff --git a/commands/control.js b/commands/control.js index c677f3f..8db425c 100644 --- a/commands/control.js +++ b/commands/control.js @@ -21,7 +21,7 @@ import { SlashCommandBuilder } from '@discordjs/builders' import { MessageEmbed, MessageActionRow, MessageButton } from 'discord.js' -import { audio } from '../AudioBackend.js' +import { audio, player, playAudio } from '../AudioBackend.js' export default { @@ -37,12 +37,38 @@ export default { const controlButtons = new MessageActionRow() .addComponents( + new MessageButton() + .setStyle('SUCCESS') + .setLabel('Play') + .setCustomId('play'), new MessageButton() .setStyle('PRIMARY') - .setLabel('Pause') - .setCustomId('soon') + .setLabel('Pause') //possible toggle button instead + .setCustomId('pause'), + new MessageButton() + .setStyle('SECONDARY') + .setLabel('Skip') + .setCustomId('skip'), + new MessageButton() + .setStyle('DANGER') + .setLabel('Leave') + .setCustomId('leave') ); + const filter = i => i.customId === 'pause' && i.user.id === '242775871059001344'; + + const collector = interaction.channel.createMessageComponentCollector({ filter, time: 15000 }); + + collector.on('collect', async i => { + if (i.customId === 'pause') { + await i.reply({content:'test'}) + } + + if (i.customId === 'skip') { + await i.reply + } + }); + return interaction.reply({embeds:[controlEmbed], components:[controlButtons]}); }, }; \ No newline at end of file diff --git a/commands/help.js b/commands/help.js index f56715c..76bd29b 100644 --- a/commands/help.js +++ b/commands/help.js @@ -30,7 +30,7 @@ export default { async execute(interaction, bot) { const helpEmbed = new MessageEmbed() .setAuthor({name:`${bot.user.username} Help`, iconURL:bot.user.avatarURL()}) - .setDescription(`Currently playing \`${audio}\`.`) + .setDescription(`Currently playing \`${audio}\``) .addField('Public Commands', `/help\n/ping\n/about\n`, true) .addField('Bot Owner Only', `/join\n/control\n/stop\n`, true) .setFooter({text:'© Copyright 2020-2022 Andrew Lee. Licensed with GPL-3.0.'}) diff --git a/deploy-command.js b/deploy-command.js index e11458a..c85637f 100644 --- a/deploy-command.js +++ b/deploy-command.js @@ -1,13 +1,13 @@ -const fs = require('node:fs'); -const { REST } = require('@discordjs/rest'); -const { Routes } = require('discord-api-types/v9'); -const config = require('./config.json'); +import fs from 'node:fs' +import { REST } from '@discordjs/rest' +import { Routes } from 'discord-api-types/v9' +import config from './config.json' assert {type: 'json'} const commands = []; const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js')); for (const file of commandFiles) { - const command = require(`./commands/${file}`); + const { default: command } = await import(`./commands/${file}`); commands.push(command.data.toJSON()); } -- cgit v1.2.3