Discord.js:当有人进入任何频道时,如何使我的机器人播放音频

时间:2020-05-20 12:46:06

标签: javascript discord.js

我发现有人在尝试相同的操作,但是我认为这是“ TypeError:oldPresence.guild.channels.get不是函数”

bot.on('voiceStateUpdate', (oldPresence, newPresence) => {
let newUserChannel = newPresence.voiceChannel
let oldUserChannel = oldPresence.voiceChannel
let textChannel = oldPresence.guild.channels.get('TEXTCHANNEL ID')
connection.join()
.then()
if(oldUserChannel === undefined && newUserChannel !== undefined) {

  if (newMember.id === 'MEMBER ID')         
  {   
     newUserChannel.join()
     .then(connection => {
        console.log("Joined voice channel!");
        const dispatcher = connection.playFile("E:\UniConverter\Downloaded\Trio.mp3");

        dispatcher.on("end", end => {newUserChannel.leave()});
     })
      .catch(console.error);

  }
         else                                      
           textChannel.send("Hello") 
         } 
} 

);

bot.login(令牌);

1 个答案:

答案 0 :(得分:0)

在最新版本的Discord.js(v12)中,correct function是:

oldPresence.guild.channels.cache.get('ID');