├── typings ├── index.d.ts ├── events │ ├── ready.d.ts │ └── messageCreate.d.ts ├── commands │ └── play.d.ts └── structures │ └── Client.d.ts ├── .gitignore ├── .gitattributes ├── .github ├── FUNDING.yml ├── dependabot.yml ├── ISSUE_TEMPLATE │ ├── ------other-issues.md │ ├── ------help.md │ ├── config.yml │ ├── ---feature-request.md │ └── ---bug-report.md ├── pull_request_template.md ├── CONTRIBUTING.md └── CODE_OF_CONDUCT.md ├── src ├── events │ ├── ready.js │ └── messageCreate.js ├── index.js ├── structures │ └── Client.js └── commands │ └── play.js ├── tsconfig.json ├── README.md ├── package.json ├── .eslintrc.json └── LICENSE /typings/index.d.ts: -------------------------------------------------------------------------------- 1 | export {}; 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .env 3 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | 2 | ko_fi: assassin1234 3 | custom: https://paypal.me/assassin118 4 | -------------------------------------------------------------------------------- /src/events/ready.js: -------------------------------------------------------------------------------- 1 | module.exports = async (client) => { 2 | console.log('Ready!'); 3 | }; -------------------------------------------------------------------------------- /typings/events/ready.d.ts: -------------------------------------------------------------------------------- 1 | declare function _exports(client: Discord.Client): Promise; 2 | export = _exports; 3 | import Discord = require('discord.js'); -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | require('dotenv').config(); 2 | const Client = require('./structures/Client'); 3 | const client = new Client({ intents: 32767 }); 4 | client.setup(); -------------------------------------------------------------------------------- /typings/events/messageCreate.d.ts: -------------------------------------------------------------------------------- 1 | declare function _exports(client: Discord.Client, message: Discord.Message): Promise; 2 | export = _exports; 3 | import Discord = require('discord.js'); -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "npm" # See documentation for possible values 4 | directory: "/" # Location of package manifests 5 | schedule: 6 | interval: "daily" 7 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "include": [ 3 | "src" 4 | ], 5 | "compilerOptions": { 6 | "allowJs": true, 7 | "declaration": true, 8 | "emitDeclarationOnly": true, 9 | "outDir": "./typings" 10 | }, 11 | } -------------------------------------------------------------------------------- /typings/commands/play.d.ts: -------------------------------------------------------------------------------- 1 | export function run(client: Discord.Client, message: Discord.Message, args: string[]): Promise; 2 | export namespace config { 3 | const name: string; 4 | const description: string; 5 | } 6 | import Discord = require("discord.js"); 7 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/------other-issues.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "\U0001F469‍\U0001F527 Other Issues" 3 | about: Issues which don't fall in above categories 4 | title: '' 5 | labels: 'misc' 6 | assignees: 'Assassin-1234' 7 | 8 | --- 9 | 10 | # Description 11 | Describe the issue faced 12 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/------help.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "\U0001F469‍\U0001F393 Help" 3 | about: Get help related to this repositories 4 | title: '' 5 | labels: help wanted, question 6 | assignees: 'Assassin-1234' 7 | 8 | --- 9 | 10 | # Requirements 11 | - [] Is the issue related to this package 12 | # Description 13 | Describe the problem faced 14 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | # Summary 2 | _Give an overview_ 3 | 4 | # Extra details 5 | _Give extra details to describe the changes_ 6 | 7 | # References 8 | [Text](reference-link-here) 9 | 10 | # Related Issue 11 | [Issue Name](provide-link-to-related-issue-if-any) 12 | 13 | # Checks 14 | - [ ] Does the bot package work as intended? 15 | -------------------------------------------------------------------------------- /typings/structures/Client.d.ts: -------------------------------------------------------------------------------- 1 | export = ExtendedClient; 2 | declare class ExtendedClient extends Client { 3 | constructor(...options: any[]); 4 | commands: Map; 5 | events: Map; 6 | queue: Map; 7 | utils: {}; 8 | setup(token?: string): ExtendedClient; 9 | loadHandlers(): ExtendedClient; 10 | } 11 | import { Client } from "discord.js"; 12 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issue_enabled: true 2 | contact_links: 3 | - name: 🦸‍♂️ Get coding help 4 | url: https://discord.gg/NAgu2FXJtn 5 | about: We help everyone in our support server. Join us to seek some help 6 | - name: 🍗 Invite Nuggies 7 | url: https://discord.com/oauth2/authorize?client_id=779741162465525790&permissions=1609952503&scope=bot%20applications.commands 8 | about: Invite Nuggies and benefit from all of it's features -------------------------------------------------------------------------------- /src/events/messageCreate.js: -------------------------------------------------------------------------------- 1 | const prefix = '&'; 2 | 3 | module.exports = async (client, message) => { 4 | if (message.author.bot || !message.channel.type.toLowerCase().startsWith('guild')) return; 5 | 6 | if (!message.content.startsWith(prefix)) return; 7 | const [commandName, ...args] = message.content.slice(prefix.length).split(' '); 8 | 9 | const command = client.commands.get(commandName); 10 | if (!command) return; 11 | 12 | command.run(client, message, args); 13 | }; -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/---feature-request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "\U0001F579 Feature request" 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: enhancement 6 | assignees: LegItMate 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Discord.js v13 music example 2 | 3 | This repository is made for helping people understand how to use `voice` in discord.js v13! 4 | This package focuses only on **music** and not any other features. 5 | 6 | Before you do use this package make sure to check out their [guide](https://discordjs.guide/voice/#installation) on v13 voice! We used it to create this bot too. 7 | 8 | ### **How to use the code?** 9 | 10 | > You will need `.env` file in which you will have your credentials(token, etc.) that is pretty much it! 11 | 12 | > Prefix is `&` if you want to know 13 | 14 | ## Contact Developers 15 | 16 | Join our [support server](https://discord.gg/Z4ebH8PXeA) to contact us! You can also create an [issue](https://github.com/Nuggies-bot/djs-music-example/issues/new/choose) if you have any queries, etc. 17 | 18 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/---bug-report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "\U0001F41E Bug report" 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: bug 6 | assignees: Assassin-1234, LegItMate 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - node version 29 | - djs version 30 | 31 | 32 | **Additional context** 33 | Add any other context about the problem here. 34 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "djs-music-example", 3 | "version": "0.0.1", 4 | "description": "An example repoistory for discord.js v13 voice!", 5 | "main": "src/index.js", 6 | "types": "./typings", 7 | "scripts": { 8 | "test": "npm i && node ." 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/Nuggies-bot/djs-music-example" 13 | }, 14 | "keywords": [ 15 | "music", 16 | "djs", 17 | "v13", 18 | "discord-js-v13" 19 | ], 20 | "author": "NuggetDev", 21 | "license": "ISC", 22 | "dependencies": { 23 | "@discordjs/opus": "^0.6.0", 24 | "@discordjs/voice": "^0.8.0", 25 | "discord.js": "^13.7.0", 26 | "dotenv": "^16.0.1", 27 | "eslint": "^8.9.0", 28 | "ffmpeg-static": "^4.4.0", 29 | "libsodium-wrappers": "^0.7.9", 30 | "youtube-sr": "^4.1.10", 31 | "ytdl-core": "^4.9.1", 32 | "ytsr": "^3.5.3" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/structures/Client.js: -------------------------------------------------------------------------------- 1 | const { Client } = require('discord.js'); 2 | const fs = require('fs'); 3 | 4 | class ExtendedClient extends Client { 5 | constructor(...options) { 6 | super(...options); 7 | 8 | this.commands = new Map(); 9 | this.events = new Map(); 10 | 11 | this.queue = new Map(); 12 | 13 | this.utils = {}; 14 | } 15 | 16 | setup(token = process.env.TOKEN) { 17 | if (!token) throw Error('No token'); 18 | this.login(token) 19 | .then(() => console.log(`Logged in as ${this.user.tag}`)) 20 | .catch((r) => console.log(r)); 21 | 22 | this.loadHandlers(); 23 | 24 | return this; 25 | } 26 | 27 | loadHandlers() { 28 | const handlers = ['events', 'commands']; 29 | 30 | handlers.forEach((handler) => { 31 | const files = fs.readdirSync(`./src/${handler.split('.')[0]}`); 32 | 33 | files.forEach((file) => { 34 | const data = require(`../${handler.split('.')[0]}/${file}`); 35 | 36 | this[handler.split('.')[0]].set(data.config?.name || file.split('.')[0], data); 37 | 38 | }); 39 | }); 40 | 41 | this.events.forEach((event, eventName) => { 42 | this.on(eventName, event.bind(null, this)); 43 | }); 44 | 45 | return this; 46 | } 47 | } 48 | 49 | module.exports = ExtendedClient; -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "eslint:recommended", 3 | "env": { 4 | "node": true, 5 | "es6": true 6 | }, 7 | "parserOptions": { 8 | "ecmaVersion": 2019 9 | }, 10 | "rules": { 11 | "brace-style": ["error", "stroustrup", { "allowSingleLine": true }], 12 | "comma-dangle": ["error", "always-multiline"], 13 | "comma-spacing": "error", 14 | "comma-style": "error", 15 | "curly": ["error", "multi-line", "consistent"], 16 | "dot-location": ["error", "property"], 17 | "handle-callback-err": "off", 18 | "indent": ["error", "tab"], 19 | "max-nested-callbacks": ["error", { "max": 4 }], 20 | "max-statements-per-line": ["error", { "max": 2 }], 21 | "no-console": "off", 22 | "no-empty-function": "error", 23 | "no-floating-decimal": "error", 24 | "no-inline-comments": "error", 25 | "no-lonely-if": "error", 26 | "no-multi-spaces": "error", 27 | "no-multiple-empty-lines": ["error", { "max": 2, "maxEOF": 1, "maxBOF": 0 }], 28 | "no-shadow": ["error", { "allow": ["err", "resolve", "reject"] }], 29 | "no-trailing-spaces": ["error"], 30 | "no-var": "error", 31 | "object-curly-spacing": ["error", "always"], 32 | "prefer-const": "error", 33 | "quotes": ["error", "single"], 34 | "semi": ["error", "always"], 35 | "space-before-blocks": "error", 36 | "space-before-function-paren": ["error", { 37 | "anonymous": "never", 38 | "named": "never", 39 | "asyncArrow": "always" 40 | }], 41 | "space-in-parens": "error", 42 | "space-infix-ops": "error", 43 | "space-unary-ops": "error", 44 | "spaced-comment": "error", 45 | "yoda": "error" 46 | } 47 | } -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | When contributing to this repository, please first discuss the change you wish to make via issue, 4 | email, or any other method with the owners of this repository before making a change. 5 | 6 | Please note we have a code of conduct, please follow it in all your interactions with the project. 7 | 8 | ## Pull Request Process 9 | 10 | 1. Ensure any install or build dependencies are removed before the end of the layer when doing a 11 | build. 12 | 2. Update the README.md with details of changes to the interface, this includes new environment 13 | variables, exposed ports, useful file locations and container parameters. 14 | 3. Increase the version numbers in any examples files and the README.md to the new version that this 15 | Pull Request would represent. The versioning scheme we use is [SemVer](http://semver.org/). 16 | 4. You may merge the Pull Request in once you have the sign-off of two other developers, or if you 17 | do not have permission to do that, you may request the second reviewer to merge it for you. 18 | 19 | ## Code of Conduct 20 | 21 | ### Our Pledge 22 | 23 | In the interest of fostering an open and welcoming environment, we as 24 | contributors and maintainers pledge to making participation in our project and 25 | our community a harassment-free experience for everyone, regardless of age, body 26 | size, disability, ethnicity, gender identity and expression, level of experience, 27 | nationality, personal appearance, race, religion, or sexual identity and 28 | orientation. 29 | 30 | ### Our Standards 31 | 32 | Examples of behavior that contributes to creating a positive environment 33 | include: 34 | 35 | * Using welcoming and inclusive language 36 | * Being respectful of differing viewpoints and experiences 37 | * Gracefully accepting constructive criticism 38 | * Focusing on what is best for the community 39 | * Showing empathy towards other community members 40 | 41 | Examples of unacceptable behavior by participants include: 42 | 43 | * The use of sexualized language or imagery and unwelcome sexual attention or 44 | advances 45 | * Trolling, insulting/derogatory comments, and personal or political attacks 46 | * Public or private harassment 47 | * Publishing others' private information, such as a physical or electronic 48 | address, without explicit permission 49 | * Other conduct which could reasonably be considered inappropriate in a 50 | professional setting 51 | 52 | ### Our Responsibilities 53 | 54 | Project maintainers are responsible for clarifying the standards of acceptable 55 | behavior and are expected to take appropriate and fair corrective action in 56 | response to any instances of unacceptable behavior. 57 | 58 | Project maintainers have the right and responsibility to remove, edit, or 59 | reject comments, commits, code, wiki edits, issues, and other contributions 60 | that are not aligned to this Code of Conduct, or to ban temporarily or 61 | permanently any contributor for other behaviors that they deem inappropriate, 62 | threatening, offensive, or harmful. 63 | 64 | ### Scope 65 | 66 | This Code of Conduct applies both within project spaces and in public spaces 67 | when an individual is representing the project or its community. Examples of 68 | representing a project or community include using an official project e-mail 69 | address, posting via an official social media account, or acting as an appointed 70 | representative at an online or offline event. Representation of a project may be 71 | further defined and clarified by project maintainers. 72 | 73 | ### Enforcement 74 | 75 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 76 | reported by contacting the project team at [INSERT EMAIL ADDRESS]. All 77 | complaints will be reviewed and investigated and will result in a response that 78 | is deemed necessary and appropriate to the circumstances. The project team is 79 | obligated to maintain confidentiality with regard to the reporter of an incident. 80 | Further details of specific enforcement policies may be posted separately. 81 | 82 | Project maintainers who do not follow or enforce the Code of Conduct in good 83 | faith may face temporary or permanent repercussions as determined by other 84 | members of the project's leadership. 85 | 86 | ### Attribution 87 | 88 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 89 | available at [http://contributor-covenant.org/version/1/4][version] 90 | 91 | [homepage]: http://contributor-covenant.org 92 | [version]: http://contributor-covenant.org/version/1/4/ 93 | -------------------------------------------------------------------------------- /.github/CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our 6 | community a harassment-free experience for everyone, regardless of age, body 7 | size, visible or invisible disability, ethnicity, sex characteristics, gender 8 | identity and expression, level of experience, education, socio-economic status, 9 | nationality, personal appearance, race, religion, or sexual identity 10 | and orientation. 11 | 12 | We pledge to act and interact in ways that contribute to an open, welcoming, 13 | diverse, inclusive, and healthy community. 14 | 15 | ## Our Standards 16 | 17 | Examples of behavior that contributes to a positive environment for our 18 | community include: 19 | 20 | * Demonstrating empathy and kindness toward other people 21 | * Being respectful of differing opinions, viewpoints, and experiences 22 | * Giving and gracefully accepting constructive feedback 23 | * Accepting responsibility and apologizing to those affected by our mistakes, 24 | and learning from the experience 25 | * Focusing on what is best not just for us as individuals, but for the 26 | overall community 27 | 28 | Examples of unacceptable behavior include: 29 | 30 | * The use of sexualized language or imagery, and sexual attention or 31 | advances of any kind 32 | * Trolling, insulting or derogatory comments, and personal or political attacks 33 | * Public or private harassment 34 | * Publishing others' private information, such as a physical or email 35 | address, without their explicit permission 36 | * Other conduct which could reasonably be considered inappropriate in a 37 | professional setting 38 | 39 | ## Enforcement Responsibilities 40 | 41 | Community leaders are responsible for clarifying and enforcing our standards of 42 | acceptable behavior and will take appropriate and fair corrective action in 43 | response to any behavior that they deem inappropriate, threatening, offensive, 44 | or harmful. 45 | 46 | Community leaders have the right and responsibility to remove, edit, or reject 47 | comments, commits, code, wiki edits, issues, and other contributions that are 48 | not aligned to this Code of Conduct, and will communicate reasons for moderation 49 | decisions when appropriate. 50 | 51 | ## Scope 52 | 53 | This Code of Conduct applies within all community spaces, and also applies when 54 | an individual is officially representing the community in public spaces. 55 | Examples of representing our community include using an official e-mail address, 56 | posting via an official social media account, or acting as an appointed 57 | representative at an online or offline event. 58 | 59 | ## Enforcement 60 | 61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 62 | reported to the community leaders responsible for enforcement at 63 | https://discord.com/invite/DXnhkJKZag. 64 | All complaints will be reviewed and investigated promptly and fairly. 65 | 66 | All community leaders are obligated to respect the privacy and security of the 67 | reporter of any incident. 68 | 69 | ## Enforcement Guidelines 70 | 71 | Community leaders will follow these Community Impact Guidelines in determining 72 | the consequences for any action they deem in violation of this Code of Conduct: 73 | 74 | ### 1. Correction 75 | 76 | **Community Impact**: Use of inappropriate language or other behavior deemed 77 | unprofessional or unwelcome in the community. 78 | 79 | **Consequence**: A private, written warning from community leaders, providing 80 | clarity around the nature of the violation and an explanation of why the 81 | behavior was inappropriate. A public apology may be requested. 82 | 83 | ### 2. Warning 84 | 85 | **Community Impact**: A violation through a single incident or series 86 | of actions. 87 | 88 | **Consequence**: A warning with consequences for continued behavior. No 89 | interaction with the people involved, including unsolicited interaction with 90 | those enforcing the Code of Conduct, for a specified period of time. This 91 | includes avoiding interactions in community spaces as well as external channels 92 | like social media. Violating these terms may lead to a temporary or 93 | permanent ban. 94 | 95 | ### 3. Temporary Ban 96 | 97 | **Community Impact**: A serious violation of community standards, including 98 | sustained inappropriate behavior. 99 | 100 | **Consequence**: A temporary ban from any sort of interaction or public 101 | communication with the community for a specified period of time. No public or 102 | private interaction with the people involved, including unsolicited interaction 103 | with those enforcing the Code of Conduct, is allowed during this period. 104 | Violating these terms may lead to a permanent ban. 105 | 106 | ### 4. Permanent Ban 107 | 108 | **Community Impact**: Demonstrating a pattern of violation of community 109 | standards, including sustained inappropriate behavior, harassment of an 110 | individual, or aggression toward or disparagement of classes of individuals. 111 | 112 | **Consequence**: A permanent ban from any sort of public interaction within 113 | the community. 114 | 115 | ## Attribution 116 | 117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 118 | version 2.0, available at 119 | https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 120 | 121 | Community Impact Guidelines were inspired by [Mozilla's code of conduct 122 | enforcement ladder](https://github.com/mozilla/diversity). 123 | 124 | [homepage]: https://www.contributor-covenant.org 125 | 126 | For answers to common questions about this code of conduct, see the FAQ at 127 | https://www.contributor-covenant.org/faq. Translations are available at 128 | https://www.contributor-covenant.org/translations. 129 | -------------------------------------------------------------------------------- /src/commands/play.js: -------------------------------------------------------------------------------- 1 | // The most basic command, play 2 | const Discord = require('discord.js'); 3 | const Voice = require('@discordjs/voice'); 4 | const ytdl = require('ytdl-core'); 5 | const yt_sr = require('youtube-sr').default; 6 | 7 | /** 8 | * @param {Discord.Client} client 9 | * @param {Discord.Message} message 10 | * @param {String[]} args 11 | */ 12 | module.exports.run = async (client, message, args) => { 13 | if (!message.member.voice.channel) return message.reply('You need to be in a voice channel.'); 14 | 15 | let queue = client.queue.get(message.guild.id); 16 | 17 | if (ytdl.validateURL(args[0])) { 18 | // Getting Info 19 | const stream = await ytdl(args[0], { highWaterMark: 1 << 25, quality: 'highestaudio', type: 'opus', filter: 'audioonly' }); 20 | let rawData = await ytdl.getBasicInfo(args[0], { 'lang': 'en' }); 21 | rawData = { 22 | url: args[0], 23 | title: rawData.videoDetails.title, 24 | bestThumbnail: rawData.videoDetails.thumbnails[0], 25 | }; 26 | 27 | // Joining 28 | const channel = message.guild.channels.cache.get(message.member.voice.channel.id); 29 | let connection = Voice.getVoiceConnection(message.guild.id); 30 | if (!connection) { 31 | connection = Voice.joinVoiceChannel({ 32 | 'adapterCreator': message.guild.voiceAdapterCreator, 33 | 'channelId': channel.id, 34 | 'guildId': message.guild.id, 35 | 'selfDeaf': true, 36 | }); 37 | } 38 | 39 | // Playing 40 | const player = Voice.createAudioPlayer(); 41 | const resource = Voice.createAudioResource(stream); 42 | player.play(resource); 43 | 44 | // Queue system 45 | const basequeue = { 46 | id: message.guild.id, 47 | startedAt: Date.now(), 48 | voiceChannel: channel, 49 | textChannel: message.channel, 50 | player: player, 51 | connection: connection, 52 | songs: [], 53 | playing: true, 54 | }; 55 | if (!queue) { 56 | queue = basequeue; 57 | client.queue.set(message.guild.id, basequeue); 58 | } 59 | 60 | if (queue.songs.length === 0) { 61 | queue.songs.push(rawData); 62 | connection.subscribe(player); 63 | player.on(Voice.AudioPlayerStatus.Idle, async () => { 64 | const newqueue = client.queue.get(message.guild.id); 65 | const removed = newqueue.songs.shift(); 66 | 67 | if (!newqueue.songs.length) { 68 | newqueue.textChannel.send('The queue has ended!'); 69 | newqueue.connection.destroy(); 70 | player.stop(); 71 | newqueue.playing = false; 72 | } 73 | else { 74 | if (!removed) return; 75 | newqueue.textChannel.send({ allowedMentions: { roles: [], parse: [], users: [] }, content: `The song \`${removed.title}\` has ended! Next up \`${newqueue.songs[0].title}\`` }); 76 | const newresource = Voice.createAudioResource(await ytdl(newqueue.songs[0].url, { highWaterMark: 1 << 25, quality: 'highestaudio', type: 'opus', filter: 'audioonly' })); 77 | player.play(newresource); 78 | } 79 | }); 80 | } 81 | else { 82 | queue.songs.push(rawData); 83 | player.stop(); 84 | } 85 | } 86 | else { 87 | // Searching 88 | const searching = await message.channel.send('Searching...'); 89 | const search = args.join(' '); 90 | if (!search || !search.length) return message.reply('Provide a query'); 91 | const res = await yt_sr.search(search, { 'limit': 4, 'type': 'video' }); 92 | const rawData = res[0]; 93 | rawData.url = `https://youtube.com/watch?v=${rawData.id}`; 94 | if (!rawData) return message.reply('Unable to find that video.'); 95 | const stream = await ytdl(rawData.url, { highWaterMark: 1 << 25, quality: 'highestaudio', type: 'opus', filter: 'audioonly' }); 96 | 97 | // Joining 98 | const channel = message.guild.channels.cache.get(message.member.voice.channel.id); 99 | let connection = Voice.getVoiceConnection(message.guild.id); 100 | if (!connection) { 101 | connection = Voice.joinVoiceChannel({ 102 | 'adapterCreator': message.guild.voiceAdapterCreator, 103 | 'channelId': channel.id, 104 | 'guildId': message.guild.id, 105 | 'selfDeaf': true, 106 | }); 107 | } 108 | 109 | // Playing 110 | const player = Voice.createAudioPlayer(); 111 | const resource = Voice.createAudioResource(stream); 112 | player.play(resource); 113 | 114 | // Queue system 115 | const basequeue = { 116 | id: message.guild.id, 117 | startedAt: Date.now(), 118 | voiceChannel: channel, 119 | textChannel: message.channel, 120 | player: player, 121 | connection: connection, 122 | songs: [], 123 | playing: true, 124 | }; 125 | if (!queue) { 126 | queue = basequeue; 127 | client.queue.set(message.guild.id, basequeue); 128 | } 129 | 130 | if (queue.songs.length === 0) { 131 | queue.songs.push(rawData); 132 | connection.subscribe(player); 133 | player.on(Voice.AudioPlayerStatus.Idle, async () => { 134 | const newqueue = client.queue.get(message.guild.id); 135 | const removed = newqueue.songs.shift(); 136 | 137 | if (!newqueue.songs.length) { 138 | newqueue.textChannel.send('The queue has ended!'); 139 | newqueue.connection.destroy(); 140 | player.stop(); 141 | newqueue.playing = false; 142 | } 143 | else { 144 | if (!removed) return; 145 | newqueue.textChannel.send({ allowedMentions: { roles: [], parse: [], users: [] }, content: `The song \`${removed.title}\` has ended! Next up \`${newqueue.songs[0].title}\`` }); 146 | const newresource = Voice.createAudioResource(await ytdl(newqueue.songs[0].url, { highWaterMark: 1 << 25, quality: 'highestaudio', type: 'opus', filter: 'audioonly' })); 147 | player.play(newresource); 148 | } 149 | }); 150 | } 151 | else { 152 | queue.songs.push(rawData); 153 | player.stop(); 154 | } 155 | 156 | await searching.delete(); 157 | } 158 | }; 159 | 160 | module.exports.config = { 161 | name: 'play', 162 | description: 'Just play songs', 163 | }; 164 | 165 | /* - ytsr.Video 166 | Video { 167 | id: 'dQw4w9WgXcQ', 168 | title: 'Rick Astley - Never Gonna Give You Up (Official Music Video)', 169 | description: null, 170 | durationFormatted: '3:33', 171 | duration: 213000, 172 | uploadedAt: '11 years ago', 173 | views: 1033562194, 174 | thumbnail: [Thumbnail], 175 | channel: [Channel], 176 | likes: 0, 177 | dislikes: 0, 178 | live: false, 179 | private: false, 180 | tags: [] 181 | } 182 | */ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------