检查传输是否完成的不和谐机器人



我的js代码有问题。我构建了一个机器人,它使用谁加入的名称制作一个文件以在我的服务器中播放,但它太快了,所以我想放一些东西来停止代码,直到它完成制作文件

client.on('voiceStateUpdate', async(oldState, newState) => {
if (!oldState || !newState) return;
const oldChannel = oldState.channel ? oldState.channel.id : null;
const newChannel = newState.channel ? newState.channel.id : null;
const user = await client.users.fetch(newState.id)
let nome = user.username;
let messaggio = 'E' entrato '+nome;
say.export(messaggio , 'Cellos', 1, 'output.wav', (err) => {
if (err) {
return console.error(err)
}
})
online(newChannel, newState, nome);
});

function online(newChannel, newState, nome) {
if(newChannel === universoVoice && newState.id !== Botid){
console.log('entrata');
const voiceChannel = client.channels.cache.get(universoVoice);
if (!voiceChannel) return console.error("The channel does not exist!");
voiceChannel.join().then(connection => {
console.log("Connesso");
connection.play('out.mp3');
client.leaveVoiceChannel;
}).catch(e => {
console.error(e);
});
}else{
console.log('uscita');
}
}

尝试使用await online(newChannel, newState, nome);以等待say.export函数完成

最新更新