Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Guild#retrieveMemberVoiceState #2729

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

PascalNB
Copy link

Pull Request Etiquette

Changes

  • Internal code
  • Library interface (affecting end-user code)
  • Documentation
  • Other: _____

Closes Issue: NaN

Description

Discord recently added an API endpoint to get a user's voice state in a guild (https://discord.com/developers/docs/resources/voice).
Adds Guild#retrieveMemberVoiceState, Guild#retrieveMemberVoiceStateById(long) and Guild#retrieveMemberVoiceStateById(String) that send a request and create a new GuildVoiceState if not already cached.

Also makes changes to EntityBuilder to allow the creation of voice states from JSON and Route for the new endpoint.

{
EntityBuilder entityBuilder = jda.getEntityBuilder();
DataObject voiceStateData = response.getObject();
MemberImpl member = entityBuilder.createMember(this, voiceStateData.getObject("member"), voiceStateData, null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not pass the voice state to createMember here since it will become stale and inconsistent.


final long channelId = voiceStateJson.getLong("channel_id");
final long channelId = newVoiceStateJson.getLong("channel_id");
AudioChannel audioChannel = (AudioChannel) guild.getGuildChannelById(channelId);
if (audioChannel != null)
((AudioChannelMixin<?>) audioChannel).getConnectedMembersMap().put(member.getIdLong(), member);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid updating the channel connected members cache unless we actually cache voice states, otherwise this cache is incredibly unreliable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants