【发布时间】:2021-04-15 23:12:01
【问题描述】:
client.on("ready", () => {
console.log(`Logged in as ${client.user.tag}`)
const voiceChannel = client.channels.cache.get(channel_id)
voiceChannel.join().then(connection => {
console.log("Joined voice channel")
function play(connection) {
const stream = ytdl(video_urls[Math.floor(Math.random() * video_urls.length)], { filter: "audioonly" })
const dispatcher = connection.play(stream)
dispatcher.on("finish", () => {
play(connection)
})
}
play(connection)
})
})
这是音乐机器人的基本代码。如果有人断开了语音通道,如何使其重新连接到语音通道? 我见过这样的代码
setInterval(async function() {
if(!client.voice.connections.get(SERVER)) {
let channel = client.channels.cache.get(CHANNEL) || await client.channels.fetch(CHANNEL)
if(!channel) return;
const connection = await channel.join()
connection.play(ytdl(LIVE))
}
}, 20000)
如何在我的实现?
【问题讨论】:
标签: javascript node.js discord.js