diff options
| author | Andrew Lee <alee14498@protonmail.com> | 2022-03-26 17:53:07 -0400 |
|---|---|---|
| committer | Andrew Lee <alee14498@protonmail.com> | 2022-03-26 17:53:07 -0400 |
| commit | 7e814d36e97bc3a7a17dcde4b5b373e647c6f6d0 (patch) | |
| tree | edc1db8fb415d3e001443c73e3b84e327c96e9f9 | |
| parent | d55e74693da3c7b2705d67aa1880baaa0dcd1790 (diff) | |
| download | DLAP-7e814d36e97bc3a7a17dcde4b5b373e647c6f6d0.tar.gz DLAP-7e814d36e97bc3a7a17dcde4b5b373e647c6f6d0.tar.bz2 DLAP-7e814d36e97bc3a7a17dcde4b5b373e647c6f6d0.zip | |
Some tweaks
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | bot.js | 21 | ||||
| -rw-r--r-- | commands/control.js | 8 | ||||
| -rw-r--r-- | commands/help.js | 11 |
4 files changed, 25 insertions, 17 deletions
@@ -24,6 +24,8 @@ Make a new file called `config.json`. Add your own audio files using the mp3 file extension to the `music` folder. +Deploy the commands by doing `node deploy-command.js` + Launch the bot using `node bot.js` in terminal. # Help Command @@ -18,11 +18,11 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. * ***************************************************************************/ -const Discord = require('discord.js'); +const { Client, MessageEmbed, Collection, version } = require('discord.js'); const fs = require('fs'); const { join } = require('node:path'); const { createAudioPlayer, createAudioResource, joinVoiceChannel, VoiceConnectionStatus, getVoiceConnection } = require('@discordjs/voice'); -const bot = new Discord.Client({intents: ['GUILDS', 'GUILD_MESSAGES', 'GUILD_VOICE_STATES']}); +const bot = new Client({intents: ['GUILDS', 'GUILD_MESSAGES', 'GUILD_VOICE_STATES']}); const config = require('./config.json'); const player = createAudioPlayer(); let audio; @@ -80,7 +80,7 @@ function playAudio() { console.log(err); }); } - const statusEmbed = new Discord.MessageEmbed() + const statusEmbed = new MessageEmbed() .addField('Now Playing', `${audio}`) .setColor('#0066ff') @@ -90,7 +90,9 @@ function playAudio() { } -bot.commands = new Discord.Collection(); +// Slash Command Handler + +bot.commands = new Collection(); const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js')); for (const file of commandFiles) { @@ -101,14 +103,13 @@ for (const file of commandFiles) { bot.once('ready', () => { console.log('Bot is ready!'); console.log(`Logged in as ${bot.user.tag}!`); - console.log(`Running on Discord.JS ${Discord.version}`) + console.log(`Running on Discord.JS ${version}`) console.log(`Prefix: ${config.prefix}`); console.log(`Owner ID: ${config.botOwner}`); console.log(`Voice Channel: ${config.voiceChannel}`); console.log(`Status Channel: ${config.statusChannel}\n`); // Set bots' presence - bot.user.setPresence({ activities: [{ name: 'some beats', @@ -121,7 +122,7 @@ bot.once('ready', () => { console.log(`Updated bot presence to "${activity.name}"`); // Send bots' status to channel - const readyEmbed = new Discord.MessageEmbed() + const readyEmbed = new MessageEmbed() .setAuthor({name:bot.user.username, iconURL:bot.user.avatarURL()}) .setDescription('Starting bot...') .setColor('#0066ff') @@ -142,7 +143,7 @@ bot.on('interactionCreate', async interaction => { if (!command) return; try { - await command.execute(interaction, bot); + await command.execute(interaction, bot, player, audio); } catch (error) { console.error(error); await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true }); @@ -159,7 +160,7 @@ bot.on('messageCreate', async msg => { // Public allowed commands if (command === 'help') { - const helpEmbed = new Discord.MessageEmbed() + const helpEmbed = new MessageEmbed() .setAuthor({name:`${bot.user.username} Help`, iconURL:bot.user.avatarURL()}) .setDescription(`Currently playing \`${audio}\`.`) .addField('Public Commands', `${config.prefix}help\n${config.prefix}ping\n${config.prefix}git\n${config.prefix}playing\n${config.prefix}about\n`, true) @@ -238,7 +239,7 @@ bot.on('messageCreate', async msg => { console.log(err); }); } - const statusEmbed = new Discord.MessageEmbed() + const statusEmbed = new MessageEmbed() .setAuthor({name:bot.user.username, iconURL:bot.user.avatarURL()}) .setDescription(`That\'s all folks! Powering down ${bot.user.username}...`) .setColor('#0066ff') diff --git a/commands/control.js b/commands/control.js index aa07991..f5846e2 100644 --- a/commands/control.js +++ b/commands/control.js @@ -1,5 +1,6 @@ const { SlashCommandBuilder } = require('@discordjs/builders'); -const { MessageEmbed, MessageActionRow, MessageButton} = require("discord.js"); +const { MessageEmbed, MessageActionRow, MessageButton } = require("discord.js"); + module.exports = { data: new SlashCommandBuilder() @@ -10,13 +11,16 @@ module.exports = { .setAuthor({name:`${bot.user.username} Control Panel`, iconURL:bot.user.avatarURL()}) .addField('Currently Playing', 'audio file here') .addField('Next Music', '(a possible feature?)') + .setColor('#0066ff') + const controlButtons = new MessageActionRow() .addComponents( new MessageButton() .setStyle('PRIMARY') - .setLabel('Pause/Play') + .setLabel('Pause') .setCustomId('soon') ); + return interaction.reply({embeds:[controlEmbed], components:[controlButtons]}); }, };
\ No newline at end of file diff --git a/commands/help.js b/commands/help.js index b4d2d86..67ed896 100644 --- a/commands/help.js +++ b/commands/help.js @@ -1,17 +1,18 @@ const { SlashCommandBuilder } = require('@discordjs/builders'); const { MessageEmbed } = require("discord.js"); +const { AudioResource } = require("@discordjs/voice"); const config = require("../config.json"); module.exports = { data: new SlashCommandBuilder() .setName('help') - .setDescription('Lists commands for the bot.'), - async execute(interaction, bot) { + .setDescription('Lists the commands'), + async execute(interaction, bot, audio) { const helpEmbed = new MessageEmbed() .setAuthor({name:`${bot.user.username} Help`, iconURL:bot.user.avatarURL()}) - //.setDescription(`Currently playing \`${audio}\`.`) - .addField('Public Commands', `${config.prefix}help\n${config.prefix}ping\n${config.prefix}git\n${config.prefix}playing\n${config.prefix}about\n`, true) - .addField('Bot Owner Only', `${config.prefix}join\n${config.prefix}resume\n${config.prefix}pause\n${config.prefix}skip\n${config.prefix}leave\n${config.prefix}stop\n`, true) + .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.'}) .setColor('#0066ff') |
