音乐机器人可以加入但无法播放文件

时间:2019-08-05 12:35:04

标签: javascript node.js discord.js

我正在编码一个不和谐的bot,我想包括一个音乐播放器,现在我正在尝试播放同一文件夹中的文件

正在从我的主文件中调用该函数。 我已经尝试了多种方法,但是都没有效果, 播放器const将在以后用于暂停简历等

(暂时忽略链接变量,稍后将其用于承载youtube链接)

function setUp(): void 
{
    parent::setUp();

    $config = $this->app['config'];
    $this->token = $config->get('app.token');
}

预期: 该机器人应加入并开始播放我的Pascal.mp3文件

实际: 机器人连接到vc,然后崩溃

module.exports = {
streamyt: function (message, link) {
    if (message.member.voiceChannel ) {
        const jchannel = message.member.voiceChannel
        jchannel.join()
        const player = jchannel.play('./Pascal.mp3')
    }
    else {
        message.reply('I cant do that,you need to be in an vc first')
    }
}

1 个答案:

答案 0 :(得分:3)

显然.play()不是jchannel对象的方法。我假设您的函数只是命名为play(),应相应地调用。

module.exports = {
streamyt: function (message, link) {
    if (message.member.voiceChannel ) {
        const jchannel = message.member.voiceChannel
        jchannel.join().then(function (connection) {
            play('./Pascal.mp3') // possibly pass connection as argument here
    }
    else {
        message.reply('I cant do that,you need to be in an vc first')
    }
}