【问题标题】:discord.js ( bot ) Error : TypeError: connection.playFile is not a functiondiscord.js(bot)错误:TypeError:connection.playFile不是函数
【发布时间】:2020-07-24 10:15:32
【问题描述】:

我不明白为什么会出现这个错误:

TypeError: connection.playFile 不是函数

我的代码:

if (message.member.voice.channel) {

  message.member.voice.channel.join()
  .then(connection => { 
    const dispatcher = connection.playFile(require("path").join(__dirname, './audio.mp3'));

    dispatcher.on('start', () => { //not working
        dispatcher.setVolume(0.70);
        console.log("Playing");
    }); 
    dispatcher.on('error', (err) => console.log(err)); //no errors

        dispatcher.on('end', end => { //working fine
            console.log("Finished");
            console.log("End: " + end);
            message.member.voiceChannel.leave()
        });
  });
  }

【问题讨论】:

    标签: javascript discord.js


    【解决方案1】:

    您正在使用 discord.js v12,playFile 现在正在播放,更多信息请参见here 这样做

      message.member.voice.channel.join()
      .then(connection => { 
        const dispatcher = connection.play(require("path").join(__dirname, './audio.mp3'));
    

    应该解决问题。

    更多信息 - https://discordjs.guide/voice/the-basics.html#the-basics

    【讨论】:

    • 谢谢!但是在 :TypeError: Cannot convert "null" to int opusscript_native_wasm.js:8 Error: "abort(TypeError: Cannot convert "null" to int). Build with -s ASSERTIONS=1 for more info."
    • 这似乎是opusscript模块本身的错误尝试使用@discordjs/opus,你可以通过npm i @discordjs/opus来安装它,如果你使用yarn,你可以通过yarn add @discordjs/opus来安装它。
    猜你喜欢
    • 1970-01-01
    • 2021-12-24
    • 2021-05-31
    • 2020-11-06
    • 2020-09-17
    • 2021-01-26
    • 2020-08-05
    • 1970-01-01
    • 2020-12-31
    相关资源
    最近更新 更多