GithubHelp home page GithubHelp logo

atahanyorganci / jukebox Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 766 KB

YouTube music bot for Discord built using discord.js and TypeScript

License: MIT License

JavaScript 4.99% Dockerfile 1.10% TypeScript 93.28% Just 0.63%
discord discord-bot discord-js youtube youtube-api bot discord-api discordjs music nodejs

jukebox's Introduction

JukeBox

Discord bot for playing music from YouTube, add JukeBox to your server via link.

About

Jukebox is simple Discord bot for playing music from YouTube directly to voice channels in the your server. Bot listens to text channels, after being summoned to play audio starts streaming only the audio portion of the given YouTube video.

How it works

JukeBox connects to the Discord API using discord.js to interact with the Discord server. It listens for messages starting with the specified command prefix (e.g., '!') in text channels. When a user sends a play command with a song name, JukeBox utilizes the YouTube API to search for the top search result for that song. Once the video is selected, JukeBox uses the ytdl-core library to download the audio portion of the YouTube video and plays it in the user's voice channel. This allows the bot to stream the music directly from YouTube to the voice channel.

Usage

Name Arguments Description
!play [song name] Plays the top result from YouTube search with the given song name.
!pause - Pauses the current audio stream.
!resume - Resumes the paused audio stream.
!skip - Skips the currently playing song. If it's the end of the queue, the bot disconnects.
!stop - Stops streaming audio and disconnects from the voice channel.
!queue - Lists all the songs in the queue along with the current song.
!np - Displays the currently playing song.
!remove [number] Removes the song with the specified number from the queue.
!volume [number] Sets the volume level of the audio stream (0-100).
!info [bot/server] Displays general information about the bot or the server.
!search [song name] Searches YouTube for the given video name and displays the first result.
!help - Prints information about available commands.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

Prerequisites

  • Node.js runtime version 18.16.0 or later, it can be downloaded from official website.
  • pnpm package manager for managing dependencies installation instructions
  • Discord bot token that is used to connect to Discord API, and can be obtained from here.
  • YouTube API key is used for authenticating queries, and can be obtained from GCP.

Developing

TypeScript compiler (tsc) is only used for typechecking for bundling ESBuild (esbuild) is used. Script build.mjs is used to invoke esbuild programmatically.

  • build: Executes the build.mjs script, which likely handles the compilation of TypeScript files into JavaScript.
  • build:watch: Uses Nodemon to watch for changes in TypeScript files and run build script
  • check: Runs the TypeScript compiler (tsc) to check the project's TypeScript code for errors.
  • check:watch: Similar to check but runs in watch mode, continuously checking for TypeScript errors during development.
  • start: Starts the bot using the compiled JavaScript bundle located in the dist directory.
  • start:watch: Uses Nodemon to watch for changes in the compiled JavaScript files and restarts the bot when changes are detected.
  • dev: Concurrently runs three npm scripts (build:watch, check:watch, and start:watch) in parallel during development.
  • test: Executes the vitest script, which likely runs the project's test suite.

Deployment

Bot is deployed on fly.io using Dockerfile.

Built Using

  • discord.js: An easy-to-use and performant library for interacting with the Discord API.
  • @discordjs/voice: Provides tools for voice-based functionalities in Discord.js.
  • ytdl-core: A library for downloading and streaming audio from YouTube.
  • winston: A versatile logging library for Node.js.
  • zod: A powerful TypeScript-first schema validation library.

Authors

jukebox's People

Contributors

atahanyorganci avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

jukebox's Issues

Repeated lines

Multiple snippets are repeated while implementing commands

if (!msg.member || !msg.guild) {
     return;
}

It is unclear when a message's member or guild would be unset. Also checking whether the user is in the same voice channel with the bot is also repeated.

if (!msg.member.voice.channel) {
    await msg.channel.send(errorMessage);
    return;
}

const { id: channelId } = msg.member.voice.channel;

if (player.channelId !== channelId) {
    await msg.channel.send(errorMessage);
    return;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.