Last active
March 11, 2022 13:11
-
-
Save aDu/eb38f73bf5b73ec7f3146ee3d92e1a3b to your computer and use it in GitHub Desktop.
A minimalistic/simple music player in a Discord voice channel, using the "eris" NodeJS Discord wrapper. Put this into your existing Eris bot.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Plays music in a Discord voice channel, using the "eris" NodeJS Discord wrapper. | |
// Requires ffmpeg (https://github.com/abalabahaha/eris/issues/470). | |
const ytdl = require('ytdl-core') | |
const VOICE_CHANNEL_ID = "VOICE_CHANNEL_ID_HERE" | |
const YOUTUBE_VIDEO = "http://www.youtube.com/watch?v=5qap5aO4i9A" | |
function joinAndPlay() { | |
bot.joinVoiceChannel(VOICE_CHANNEL_ID).catch((err) => { | |
console.error("Error joining vc: " + err.message) | |
}).then((connection) => { | |
connection.play(ytdl(YOUTUBE_VIDEO, { audioonly: true })) | |
connection.once("end", joinAndPlay) | |
connection.once("error", joinAndPlay) | |
}) | |
} | |
bot.on('ready', (evt) => { | |
joinAndPlay() | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment