我正在制作一个 24/7 音乐不和谐机器人。它会在 YouTube 上 24/7 全天候播放链接。它只播放了 5 个小时,然后关闭了音乐,尽管机器人仍然在线并且 YouTube 上的音乐链接仍在播放,可能是因为 YouTube 的错误。
现在我希望机器人每 10 分钟重新连接一次 YouTube,但我不知道该怎么做。
const { TOKEN, CHANNEL, SERVER, STATUS, LinkLIVE } = require("./config.json");
const discord = require("discord.js");
const client = new discord.Client();
const ytdl = require('ytdl-core');
client.on('ready', async () => {
client.user.setActivity(STATUS + " ????? ????????")
let channel = client.channels.cache.get(CHANNEL) || await client.channels.fetch(CHANNEL)
if(!channel) return;
const connection = await channel.join();
connection.play(ytdl(LinkLIVE))
})
var i = 0;
for (i = 0; i > 1 ; i++){
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(LinkLIVE))
}
}, 20000)
}
client.login(TOKEN)