How to get my microphone status on discord

Viewed 1323

I am creating light for desk, this light will be green when my microphone is active on Discord, and red when my microphone is muted. So I want to get my microphone status from discord. But I don't know-how.

  1. How to get my microphone status from discord when I am not in a voice chat too?

I know how to get microphone status when I am sitting on voice chat but I want to get this information the whole time.

Thanks.

1 Answers

You can use Client#voiceStateUpdate to detect when you change if you are muted or not.

client.on('voiceStateUpdate', (oldState, newState) => {
  if (oldState.member.user.id !== "youridhere") return // make sure its only checking for your microhpone
  if (newState.mute) { // check if mic is muted
    setLightColor("red") //if true make light red
  } else {
    setLightColor("green") //if false make light green
  }
})
Related