繁体   English   中英

Discord.js bot 加入语音通道但加入后不会运行剩余代码

[英]Discord.js bot joining voice channel but wont run the remaining code after joining

我有一个 discord 机器人,我正试图加入一个语音频道并让它重复一个声音文件,到目前为止我已经加入但在它加入后,箭头 function 中的代码都没有运行

let channel = client.channels.cache.get('723620872572895243')

channel.join(connection => {
    console.log("Starting")
    mp3("speech.mp3", function (err, duration) {
        if (err) return console.log(err);
        console.log("File duration:" + duration * 1000 + "ms")
        repeat(connection, duration)
    })
}).catch(console.error)

这是我试图运行的代码,但它加入了通道,并且在箭头 function 运行后什么也没有

这是 repeat() function 以防万一

function repeat(connection, duration) {
const dispatcher = connection.play("speech.mp3")
let play = setInterval(function () {
    const dispatcher = connection.play("speech.mp3")
    console.log("Playing")
}, duration * 1000 + 2000)
module.exports.interval = play
}

VoiceChannel#join不带任何参数。 您还没有正确形成箭头 function ,这就是为什么您的代码都不起作用的原因,您需要在.join() .then()之后使用 .then() ,如下所示:

let channel = client.channels.cache.get('723620872572895243')

channel.join().then(connection => {
    console.log("Starting")
    mp3("speech.mp3", function (err, duration) {
        if (err) return console.log(err);
        console.log("File duration:" + duration * 1000 + "ms")
        repeat(connection, duration)
    });
}).catch(console.error)

您可以在此处查看有关VoiceChannel#join方法的更多信息

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM