Music Streaming Player for Discord with Google Drive using Node.js



This is a sample script for the music streaming player for Discord with Google Drive using Node.js.


This sample script can achieve to play the music when uses the voice channel on Discord. The music files are put in the specific folder of Google Drive. This script downloads all music files and plays the music files at the voice channel with the stream.


1. Register BOT to Discord

At first, please register your BOT to Discord. And please retrieve the token.

2. Sample script

When you use this, please set the variables of auth, token and folderId. And after you run the script, please input the text of play to the voice channel. By this, the files in the specific folder on Google Drive are loaded and are played at the voice channel on Discord.

function playFiles(obj) {
  if (obj.files.length == 0) {"end");; // <--- Important
      fileId: obj.files[0].id,
      alt: "media"
    { responseType: "stream" },
    (err, { data }) => {
      if (err) throw new Error(err);
      console.log(obj.files[0]);`Playing ${obj.files[0].name}`);
        .on("end", () => {
        .on("error", err => console.log(err));

function main(auth) {
  const token = "###"; // Please set your token for Discord.
  const folderId = "###"; // Please set the folder ID of Google Drive.

  client.on("message", message => {
    const channel = message.member.voiceChannel;
    if (channel && message.content == "play") {
      const drive ={ version: "v3", auth });
          q: `'${folderId}' in parents`,
          fields: "files(id,name)"
        (err, { data }) => {
          if (err) throw new Error(err);
            .then(connection => {
              let obj = {
                drive: drive,
                channel: channel,
                connection: connection,
                message: message,
                files: data.files
            .catch(err => console.log(err));


  • About the authorization for using Drive API, please check the Quickstart of Node.js at the official document. In this script, it supposes that the object of auth can be used for downloading the files from Google Drive.

  • In this case, channel.leave() is very important. Because I confirmed that when this is not used, there are the cases that at the next play, the sound cannot be listened from 2nd file. Please be careful this.

  • This script used discord.js. So please add the following script.

const Discord = require("discord.js");
const client = new Discord.Client();