Linked Questions

Popular Questions

I'm adding a basic music command to my Discord.js bot (big surprise), and it works fine locally (on my laptop); but when being run on a Virtual Server, throws a invalid ELF header error when attempting to play music.

More specifically, the bot's music command works on the Virtual Server up until it tries to play the music. It joins the Voice Channel fine, and I'm able to use another command to make it leave said Channel just fine.

I'm using Discord.js (11.4.2) for the bot, and node-opus with ytdl-core for the music command(s). My local machine is a Windows 10 OS, and I assume the Virtual Server is using Linux (DigitalOcean.com).

I've tried doing a npm rebuild in the Virtual Server, but that throws up another error (which I hope is not part of this problem).

This is the whole 'ELF header' error:

Error: /root/node_modules/node-opus/build/Release/node-opus.node: invalid ELF header
    at Object.Module._extensions..node (module.js:681:18)
    at Module.Load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at bindings (/root/node_modules/bindings/bindings.js:76:44)
    at Object.<anonymous> (/root/node_modules/node-opus/lib/OpusEncoder.js:4:34)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)

The code in question:

const Discord = require('discord.js');
const { client } = require('../mybot.js');
const { fs } = require('../mybot.js');
const ytdl = require('ytdl-core');

module.exports = {
    name: 'music',
    description: 'The musical set of commands!',
    usage: '<play> <YouTube Link> | <stop>',
    guildOnly: true,
    args: true,
    extraInfo: 'Requires you to be a Voice Channel to work.\nRequires a YouTube link when using \`play\`.',
    execute(message, args) {
        //Delcaring stuff
        const streamOptions = { seek: 0, volume: 1, passes: 2 };

        if(!message.guild) return; //Just in case cmd is not used in Guild

        //For getting the bot to join the VC you are in
        if(args[0] === 'play') {
          // Only try to join the sender's voice channel if they are in one themselves
          if (message.member.voiceChannel) {
            message.member.voiceChannel.join()
            .then(connection => { // Connection is an instance of VoiceConnection
              //For getting the YT URL
              const data = args.pop();
              String(data);
              console.log(data);
              //For playing the music itself
              const stream = ytdl(data, { filter : 'audioonly' }); //Downloads the audio of the video
              const dispatcher = connection.playStream(stream, streamOptions); //Plays the audio
              message.reply('Music successfully loaded.');
            })
            .catch(console.log);
          } else {
            message.reply('You need to join a voice channel first!');
          }
        } else if(args[0] === 'stop') { //For stopping the music and leaving the VC
          message.member.voiceChannel.connection.disconnect();
        }
    },
};

Of course, I'm expecting to have the bot simply join the Voice Channel I'm in, and play the audio of the YouTube video link I give it.

Any help would be great!

Related Questions