bwmarrin / discordgo

(Golang) Go bindings for Discord
BSD 3-Clause "New" or "Revised" License
5.01k stars 796 forks source link

[question] How i can obtain current voice connection #395

Closed averrin closed 6 years ago

averrin commented 7 years ago

Hi. I want add handler to current voice connection, but i cant understand how i can do it. When i authorized as bot i can join to voice channel and get connection as result, but when i connecting with email and password, and my user connects from other client i want to get current voice connection.

Update: Why i want this? I need handle speaking events but i dont want use bot for this. Can i did it without joining to voice channel from my code?

Hinara commented 7 years ago

You can't, for example if you try to do that with an other discord official client it will say you that's you are already connected from an other location, so you can connect multiple time to the gateway, but you can connect only one time to the voice server (which is used by your other client).

averrin commented 7 years ago

So, for detecting speaking events i have no other way but connecting to this channel as bot?

Hinara commented 7 years ago

I think there is a way with RPC. You need to connect via RPC your application to your Client, and from there you can get the Speaking event of your current voice server. That what XSplit and OBS do to display if someone is speaking or not in the streaming overlay. The difference is that this method will use your current client to get all the information instead of an other connection to discord. However for now RPC communication is in private beta so i'm not sure that you can use it.

iopred commented 7 years ago

For detecting when other users are speaking:

g, err := session.State.Guild(guildID) if err != nil { return err }

g.VoiceStates // <- look at this

On Sun, Jun 25, 2017 at 4:56 AM, robbix1206 notifications@github.com wrote:

I think there is a way with RPC. You need to connect vie RPC an application to your Client, and from there you can get the Speaking event of your current voice server. That what XSplit and OBS do to display if someone is speaking or not in the streaming overlay. However for now RPC communication is in private beta so i'm not sure that you can use it.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/bwmarrin/discordgo/issues/395#issuecomment-310898503, or mute the thread https://github.com/notifications/unsubscribe-auth/ABdVglMwvYU1_UEiFpjuOAbyAlzkXAWyks5sHkrrgaJpZM4OEae5 .

averrin commented 7 years ago

VoiceState have no Speaking flag. And I think I cannot add handler for this, due to its other connection with nil as voiceConnections. Variant with bot is working, but it has some other difficulties.

bwmarrin commented 7 years ago

I'm unsure what difficulties you're still having :(. Can you give a list or maybe just hop on the Discord Gophers chat (see README)? It might be easier to help you there where we can have a conversation about what you're trying to do and what isn't working.

Hinara commented 7 years ago

@averrin Did you find the answer to your problem?

averrin commented 7 years ago

@robbix1206 im still waiting for rpc. But as working solution: use password for creating bot and relogin as bot for connecting to same channel and handle events. Ugly but works.