首页 > 解决方案 > discord.js(bot)错误:TypeError:connection.playFile不是函数

问题描述

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

类型错误: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()
        });
  });
  }

标签: javascriptdiscord.js

解决方案


您正在使用 discord.js v12,playFile 现在正在播放,更多信息 在这里

  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


推荐阅读