Skip to content

Instantly share code, notes, and snippets.

@aDu
Last active March 11, 2022 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aDu/eb38f73bf5b73ec7f3146ee3d92e1a3b to your computer and use it in GitHub Desktop.
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.
// 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