检查传输是否完成的discord机器人

时间:2020-06-01 19:30:50

标签: javascript node.js bots discord

我的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');
  }
}

1 个答案:

答案 0 :(得分:0)

尝试使用await online(newChannel, newState, nome);,以便等到say.export功能完成