├── config ├── .env └── config.json ├── README.md ├── commands.js ├── LICENSE └── index.js /config/.env: -------------------------------------------------------------------------------- 1 | TOKEN=YOUR_BOT_TOKEN_NO_SPACING 2 | -------------------------------------------------------------------------------- /config/config.json: -------------------------------------------------------------------------------- 1 | { 2 | 3 | "TOKEN" : "YOUR_BOT_TOKEN" 4 | 5 | } 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Music-Bot 2 | A Discord.js Music Bot 3 | 4 | ### How To Setup ? 5 | 6 | 7 | 1. First Do `git clone https://github.com/BotStudios/Music-Bot.git` In Your Terminal 8 | 9 | 10 | 2. After Clonning The Repo, Do `cd Music-Bot` 11 | 12 | 13 | 3. Then `npm i` 14 | 15 | 16 | 4. Replace YOUR_TOKEN To Your Bot's Token In index.js 17 | 18 | 19 | 5. Done 20 | 21 | 22 | #### Note 23 | 24 | > Use .env To Store Your Token 25 | 26 | > Use config To Store Your Token 27 | 28 | 29 | Make Sure To Join Our [DISCORD SERVER](https://discord.gg/s56rMHNwhC) If You Need More Help 30 | -------------------------------------------------------------------------------- /commands.js: -------------------------------------------------------------------------------- 1 | const downloadYT = require('ytdl-core'); 2 | const searchYT = require('yt-search'); 3 | 4 | async function play(msg, ...args) { 5 | const vc = msg.member.voice.channel; 6 | 7 | const connection = await vc.join(); 8 | const video = await findVideo(args.join(' ')); 9 | 10 | if (video) { 11 | const stream = downloadYT(video.url, { filter: 'audioonly' }); 12 | connection.play(stream, { seek: 0, volume: 1 }); 13 | 14 | await msg.reply(`Now playing \`${video.title}\`.`); 15 | } else 16 | await msg.reply(`No results found.`); 17 | } 18 | async function findVideo(query) { 19 | const result = await searchYT(query); 20 | return (result.videos.length > 1) 21 | ? result.videos[0] 22 | : null; 23 | } 24 | 25 | async function stop(msg) { 26 | const vc = msg.member.voice.channel; 27 | await vc.leave(); 28 | 29 | await msg.reply('Stopped.'); 30 | } 31 | 32 | module.exports.play = play; 33 | module.exports.stop = stop; 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Bots Studios 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const Discord = require('discord.js'); 2 | const { Client, Collection } = require("discord.js") 3 | const { readdirSync } = require("fs") 4 | const { play, stop } = require('./commands.js'); 5 | const client = new Discord.Client(); 6 | client.login("YOUR_BOT_TOKEN"); 7 | 8 | client.on('ready', () => console.log('Bot has logged in!')); 9 | client.on("ready", () => { 10 | client.user.setActivity("BotStudios", { type: "STREAMING", url: "https://www.twitch.tv/BotStudiosGithub" }) 11 | }) 12 | client.on('message', (msg) => { 13 | if (msg.author.bot) return; 14 | 15 | const prefix = '-'; //can set the prefix default is - 16 | if (!msg.content.startsWith(prefix)) return; 17 | 18 | const commandName = getCommandName(prefix, msg.content); 19 | const args = getCommandArgs(prefix, msg.content); 20 | 21 | if (commandName === 'p') 22 | return play(msg, args); 23 | else if (commandName === 's') 24 | return stop(msg, args); 25 | 26 | if (commandName === 'play') 27 | return play(msg, args); 28 | else if (commandName === 'stop') 29 | return stop(msg, args); 30 | }); 31 | function getCommandName(prefix, content) { 32 | return content 33 | .slice(prefix.length) 34 | .split(' ')[0]; 35 | } 36 | function getCommandArgs(prefix, content) { 37 | return content 38 | .slice(prefix.length) 39 | .split(' ') 40 | .slice(1); 41 | } 42 | 43 | // coded by BotStudios Team 44 | // Version 2 45 | --------------------------------------------------------------------------------