我有一个不和谐的机器人,我试图让它加入一个语音通道,并让它重复一个声音文件,到目前为止,我已经让它加入,但在它加入后,箭头函数中的任何代码都没有运行
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)
这是我试图运行的代码,但它加入了通道,并且在箭头函数运行后什么也没有
下面是repeat()函数,以备需要时使用
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
}
发布于 2021-01-29 20:24:09
VoiceChannel#join
不带任何参数。你没有正确地构造箭头函数,这就是为什么你的代码都不能正常工作的原因,你需要在.join()
后面有这样的.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
方法here的更多信息
https://stackoverflow.com/questions/65959652
复制相似问题