Renamed project; Auto creates music folder when not detected; Removed audio limitation

This commit is contained in:
Andrew Lee 2022-03-30 16:34:24 -04:00
parent fd89e36490
commit 3f81f1086f
Signed by: andrew
GPG key ID: 4DCE67C47836D125
14 changed files with 53 additions and 50 deletions

2
.gitignore vendored
View file

@ -1,7 +1,7 @@
config.json
node_modules
yarn.lock
music/*.mp3
music
package-lock.json
now-playing.txt
.idea/

View file

@ -1,6 +1,6 @@
/**************************************************************************
*
* DLMP3 Bot: A Discord bot that plays local MP3 audio tracks.
* DLAP Bot: A Discord bot that plays local audio tracks.
* (C) Copyright 2022
* Programmed by Andrew Lee
*
@ -64,20 +64,12 @@ export async function voiceInit(bot) {
export async function searchAudio(bot){
//TODO: Eventually this system will need a rework so it won't repeat the same files.
while (true) {
audio = files[Math.floor(Math.random() * files.length)];
console.log('Searching .mp3 file...');
if (audio.endsWith('.mp3')) {
break;
}
}
audio = files[Math.floor(Math.random() * files.length)];
return await playAudio(bot);
}
export async function inputAudio(bot, integer) {
audio = files[integer]
audio = files[integer];
return await playAudio(bot);
}
@ -86,6 +78,7 @@ export async function playAudio(bot) {
await player.play(resource);
audio = audio.split('.').slice(0, -1).join('.');
console.log('Now playing: ' + audio);
if (config.txtFile === true) {
@ -107,7 +100,6 @@ export async function playAudio(bot) {
}
export function destroyAudio(interaction) {
if (config.txtFile === true) {
fileData = "Now Playing: Nothing";
fs.writeFile("now-playing.txt", fileData, (err) => {

View file

@ -1,6 +1,6 @@
# DLMP3 Bot (Discord.JS Local MP3)
# DLAP Bot (Discord.JS Local Audio Player)
A Discord bot that plays local MP3 audio tracks. Written in Discord.JS.
A Discord bot that plays local audio tracks. Written in Discord.JS.
[Video Tutorial](https://www.youtube.com/watch?v=7X3FAhYW31I)
@ -20,9 +20,11 @@ Make a new file called `config.json`.
}
```
Add your own audio files using the mp3 file extension to the `music` folder.
Create the `music` folder.
Deploy the commands by doing `node deploy-command.js`
Add your own audio files to the `music` folder.
Deploy the commands by doing `node deploy-command.js`.
Launch the bot using `node bot.js` in terminal.
@ -48,7 +50,7 @@ stop - Stops bot.
# Forking
When forking the project, you can make your own version of DLMP3 or help contribute to the project (See the "Contributing" section).
But you need to edit `/commands/about.js` to uncomment the `.addField('Forked by', '[your name] (discord#0000)')` section.
You need to edit `/commands/about.js` to uncomment the `.addField('Forked by', '[your name] (discord#0000)')` section.
Be sure to replace that with your name.

23
bot.js
View file

@ -1,6 +1,6 @@
/**************************************************************************
*
* DLMP3 Bot: A Discord bot that plays local MP3 audio tracks.
* DLMP3 Bot: A Discord bot that plays local audio tracks.
* (C) Copyright 2022
* Programmed by Andrew Lee
*
@ -18,18 +18,27 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
***************************************************************************/
import { Client, MessageEmbed, Collection, version } from "discord.js"
import { voiceInit } from "./AudioBackend.js"
import fs from "fs"
import config from './config.json' assert {type: 'json'}
import { Client, MessageEmbed, Collection, version } from 'discord.js'
import { voiceInit } from './AudioBackend.js'
import fs from 'fs'
import config from './config.json' assert { type: 'json' }
import path from 'path'
export const bot = new Client({intents: ['GUILDS', 'GUILD_MESSAGES', 'GUILD_VOICE_STATES']});
const dir = './music';
bot.login(config.token);
if (fs.existsSync(dir)) {
console.log('Music folder detected');
bot.login(config.token);
} else {
console.log('Directory not found. Creating music folder...');
console.log('Insert your beats to that folder.');
fs.mkdirSync(dir);
process.exit(0);
}
/**
* Project Ideas:
* Play directly the MP3 file
* New queue system
* List MP3 files
* Shuffle or "Play by order" mode

View file

@ -1,6 +1,6 @@
/**************************************************************************
*
* DLMP3 Bot: A Discord bot that plays local MP3 audio tracks.
* DLAP Bot: A Discord bot that plays local audio tracks.
* (C) Copyright 2022
* Programmed by Andrew Lee
*
@ -21,6 +21,7 @@
import { SlashCommandBuilder } from '@discordjs/builders'
import { MessageEmbed, version, MessageActionRow, MessageButton } from 'discord.js'
import npmPackage from '../package.json' assert { type:'json' }
export default {
data: new SlashCommandBuilder()
@ -30,6 +31,7 @@ export default {
const aboutEmbed = new MessageEmbed()
.setAuthor({name:`About ${bot.user.username}`, iconURL:bot.user.avatarURL()})
.addField('Information', 'A Discord bot that plays local MP3 audio tracks.')
.addField('Version', npmPackage.version)
.addField('Original Creator', 'Andrew Lee (Alee#4277)')
//.addField('Contributors', '[your name] (discord#0000)')
//.addField('Forked by', '[your name] (discord#0000)')

View file

@ -1,6 +1,6 @@
/**************************************************************************
*
* DLMP3 Bot: A Discord bot that plays local MP3 audio tracks.
* DLAP Bot: A Discord bot that plays local audio tracks.
* (C) Copyright 2022
* Programmed by Andrew Lee
*
@ -21,7 +21,7 @@
import { SlashCommandBuilder } from '@discordjs/builders'
import { MessageEmbed, MessageActionRow, MessageButton } from 'discord.js'
import {audio, player, destroyAudio, voiceInit, stopBot, searchAudio} from '../AudioBackend.js'
import { audio, player, destroyAudio, voiceInit, stopBot, searchAudio } from '../AudioBackend.js'
import config from '../config.json' assert {type: 'json'}
export let controlEmbed
@ -42,11 +42,11 @@ export default {
const controlButtons = new MessageActionRow()
.addComponents(
new MessageButton()
.setStyle('SECONDARY')
.setStyle('SUCCESS')
.setLabel('Join')
.setCustomId('join'),
new MessageButton()
.setStyle('SUCCESS')
.setStyle('PRIMARY')
.setLabel('Play')
.setCustomId('play'),
new MessageButton()
@ -54,7 +54,7 @@ export default {
.setLabel('Pause')
.setCustomId('pause'),
new MessageButton()
.setStyle('DANGER')
.setStyle('SECONDARY')
.setLabel('Skip')
.setCustomId('skip'),
new MessageButton()
@ -86,35 +86,35 @@ export default {
collector.on('collect', async ctlButton => {
if (ctlButton.customId === 'join') {
await ctlButton.reply({content:'Joining voice channel', ephemeral:true})
await voiceInit(bot);
return await voiceInit(bot);
}
if (ctlButton.customId === 'play') {
await ctlButton.reply({content:'Resuming music', ephemeral:true})
player.unpause();
return player.unpause();
}
if (ctlButton.customId === 'pause') {
await ctlButton.reply({content:'Pausing music', ephemeral:true})
player.pause();
return player.pause();
}
if (ctlButton.customId === 'skip') {
await ctlButton.reply({content:`Skipping \`${audio}\`...`, ephemeral:true})
player.pause();
await searchAudio(bot);
player.stop();
return await searchAudio(bot);
}
if (ctlButton.customId === 'next') {
await interaction.editReply({ components: [controlButtons2] });
return await interaction.editReply({ components: [controlButtons2] });
}
if (ctlButton.customId === 'back') {
await interaction.editReply({ components: [controlButtons] });
return await interaction.editReply({ components: [controlButtons] });
}
if (ctlButton.customId === 'leave') {
await ctlButton.reply({content:'Leaving voice channel.', ephemeral:true})
console.log('Leaving voice channel...');
destroyAudio(interaction);
return destroyAudio(interaction);
}
if (ctlButton.customId === 'stop') {
await ctlButton.reply({content:'Powering off...', ephemeral:true})
await stopBot(bot, interaction);
return await stopBot(bot, interaction);
}
});

View file

@ -1,6 +1,6 @@
/**************************************************************************
*
* DLMP3 Bot: A Discord bot that plays local MP3 audio tracks.
* DLAP Bot: A Discord bot that plays local audio tracks.
* (C) Copyright 2022
* Programmed by Andrew Lee
*

View file

@ -1,6 +1,6 @@
/**************************************************************************
*
* DLMP3 Bot: A Discord bot that plays local MP3 audio tracks.
* DLAP Bot: A Discord bot that plays local audio tracks.
* (C) Copyright 2022
* Programmed by Andrew Lee
*

View file

@ -1,6 +1,6 @@
/**************************************************************************
*
* DLMP3 Bot: A Discord bot that plays local MP3 audio tracks.
* DLAP Bot: A Discord bot that plays local audio tracks.
* (C) Copyright 2022
* Programmed by Andrew Lee
*

View file

@ -1,6 +1,6 @@
/**************************************************************************
*
* DLMP3 Bot: A Discord bot that plays local MP3 audio tracks.
* DLAP Bot: A Discord bot that plays local audio tracks.
* (C) Copyright 2022
* Programmed by Andrew Lee
*

View file

@ -1,6 +1,6 @@
/**************************************************************************
*
* DLMP3 Bot: A Discord bot that plays local MP3 audio tracks.
* DLAP Bot: A Discord bot that plays local audio tracks.
* (C) Copyright 2022
* Programmed by Andrew Lee
*
@ -32,7 +32,7 @@ export default {
.addIntegerOption(option =>
option.setName('int')
.setDescription('Input a number for the selection for the audio file.')
.setRequired(true),
.setRequired(false),
),
async execute(interaction, bot) {
if (![config.botOwner].includes(interaction.user.id)) return await interaction.reply({ content: "You do not have permissions to execute this command.", ephemeral: true });

View file

@ -1,6 +1,6 @@
/**************************************************************************
*
* DLMP3 Bot: A Discord bot that plays local MP3 audio tracks.
* DLAP Bot: A Discord bot that plays local audio tracks.
* (C) Copyright 2022
* Programmed by Andrew Lee
*

View file

@ -1,2 +0,0 @@
# Put your music here
Any mp3 file should go here.

View file

@ -1,6 +1,6 @@
{
"name": "dlmp3",
"version": "1.0.0",
"version": "1.2.0",
"type": "module",
"main": "bot.js",
"license": "GPL-3.0",