我发现有人在尝试相同的操作,但是我认为这是“ 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(令牌);
答案 0 :(得分:0)
在最新版本的Discord.js(v12)中,correct function是:
oldPresence.guild.channels.cache.get('ID');