How to check if user is talking

I know I should use the SpeakingMap from @discordjs/voice, but idk how to set it up to work.
23 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
𝓟𝓸𝓵𝓲𝓼𝓱𝓚𝓮𝓫𝓪𝓫 | a.k.a Kebab
discord.js@14.6.0, node v18.7.0
chewie 🌈
chewie 🌈2y ago
Well, connection.receiver.speaking.users returns the currently speaking users, mapped to the milliseconds since UNIX epoch at which they started speaking.
𝓟𝓸𝓵𝓲𝓼𝓱𝓚𝓮𝓫𝓪𝓫 | a.k.a Kebab
and connection is getVoiceConnection(guildId) from @discordjs/voice, right?
chewie 🌈
chewie 🌈2y ago
yes
𝓟𝓸𝓵𝓲𝓼𝓱𝓚𝓮𝓫𝓪𝓫 | a.k.a Kebab
why is it returning undefined? by it i mean connection
const connection = getVoiceConnection(bot.config.guildId) // bot.config.guildId returns a guild id
setInterval(()=>console.log(connection.receiver.speaking.users),1000)
const connection = getVoiceConnection(bot.config.guildId) // bot.config.guildId returns a guild id
setInterval(()=>console.log(connection.receiver.speaking.users),1000)
[uncaughtException]: TypeError: Cannot read properties of undefined (reading 'receiver')
at Timeout._onTimeout (D:\Boty\Frog bot\events\ready.js:11:44)
at listOnTimeout (node:internal/timers:564:17)
at process.processTimers (node:internal/timers:507:7)
[uncaughtException]: TypeError: Cannot read properties of undefined (reading 'receiver')
at Timeout._onTimeout (D:\Boty\Frog bot\events\ready.js:11:44)
at listOnTimeout (node:internal/timers:564:17)
at process.processTimers (node:internal/timers:507:7)
theres people inside vc talking on that guild
setInterval(()=>{
const connection = getVoiceConnection(bot.config.guildId)
console.log(connection)
},1000)
setInterval(()=>{
const connection = getVoiceConnection(bot.config.guildId)
console.log(connection)
},1000)
undefined
undefined
im in the vc talking now, why is it undefined... ): i have GuildVoiceStates intent
chewie 🌈
chewie 🌈2y ago
because thats not how you make a voice connection?
𝓟𝓸𝓵𝓲𝓼𝓱𝓚𝓮𝓫𝓪𝓫 | a.k.a Kebab
how to make a voice connection then
chewie 🌈
chewie 🌈2y ago
const connection = joinVoiceChannel({ channelId: channel.id, guildId: channel.guild.id, adapterCreator: channel.guild.voiceAdapterCreator, });
𝓟𝓸𝓵𝓲𝓼𝓱𝓚𝓮𝓫𝓪𝓫 | a.k.a Kebab
so i can only check if bot is in voice channel?
chewie 🌈
chewie 🌈2y ago
well yes obviously
𝓟𝓸𝓵𝓲𝓼𝓱𝓚𝓮𝓫𝓪𝓫 | a.k.a Kebab
is there a way to check for without the bot being in a voice channel? i want the bot to check for the voice activity in multiple channels and this way i think it wont be possible
chewie 🌈
chewie 🌈2y ago
no
𝓟𝓸𝓵𝓲𝓼𝓱𝓚𝓮𝓫𝓪𝓫 | a.k.a Kebab
some guy told me to use the SpeakingMap, would that work?
chewie 🌈
chewie 🌈2y ago
that is SpeakingMap
𝓟𝓸𝓵𝓲𝓼𝓱𝓚𝓮𝓫𝓪𝓫 | a.k.a Kebab
vaid, connection.receiver.speaking is a SpeakingMap...
chewie 🌈
chewie 🌈2y ago
the bot needs to be in the channel to receive voice data
𝓟𝓸𝓵𝓲𝓼𝓱𝓚𝓮𝓫𝓪𝓫 | a.k.a Kebab
heck it, then i guess i cant make anty vc afk
chewie 🌈
chewie 🌈2y ago
"anti vc afk" whats that supposed to be
𝓟𝓸𝓵𝓲𝓼𝓱𝓚𝓮𝓫𝓪𝓫 | a.k.a Kebab
basically i have a economy bot, and want to make it so you get money for talking in vc's, but i want to prevent people from just joining vc, muted and just there to farm money
chewie 🌈
chewie 🌈2y ago
why are you trying to implement a feature that discord already has?
chewie 🌈
chewie 🌈2y ago
once someone joins that channel -> disconnect them?
𝓟𝓸𝓵𝓲𝓼𝓱𝓚𝓮𝓫𝓪𝓫 | a.k.a Kebab
so this feature will disconnect users when they are not talking for a certain period of time? nvm, i read the desc so i could you setup a inactive channel and ignore it thx @thehairy , you really helped me a lot