public void ConnectToChannel(string guildId, string channelId) { BasicPacket packet = new VoiceStateUpdate(guildId, channelId); foreach (MainSocket ms in shards) { ms.Send(packet); } }
/// <summary> /// Method to call on VoiceStateUpdates. /// </summary> /// <param name="packet"> VoiceStateUpdatePacket you get from the Discord API. </param> /// <returns> A Task resolving with a Bool what shows if the changes went through to the server. </returns> public Task <bool> VoiceStateUpdateAsync(VoiceStateUpdate packet) { if (packet.UserID != _config.UserID) { return(Task.FromResult(false)); } if (VoiceStates.ContainsKey(packet.GuildID)) { VoiceStates[packet.GuildID] = packet.SessionID; } else { VoiceStates.Add(packet.GuildID, packet.SessionID); } return(ConnectVoiceAsync(packet.GuildID)); }
public void UpdateVoiceState(string guildID, string channelId, bool selfDeaf, bool selfMute) { var voiceState = new VoiceStateUpdate() { ChannelID = channelId, GuildID = guildID, SelfDeaf = selfDeaf, SelfMute = selfMute }; var packet = new RPayload() { OpCode = OpCodes.VoiceStateUpdate, Data = voiceState }; string payload = JsonConvert.SerializeObject(packet); _webSocket.Send(payload); }
private void HandleDispatchEvent(GatewayPayload evnt, TaskCompletionSource <bool> readySignal) { switch (evnt.DispatchType) { case GatewayDispatchType.Ready: var readyEvent = evnt.Data as ReadyEvent; SetSession(readyEvent.SessionId); readySignal.TrySetResult(true); Ready?.Invoke(readyEvent); break; case GatewayDispatchType.Resumed: readySignal.TrySetResult(true); Resumed?.Invoke(); break; case GatewayDispatchType.GuildCreate: GuildCreate?.Invoke(evnt.Data as GatewayGuild); break; case GatewayDispatchType.GuildUpdate: GuildUpdate?.Invoke(evnt.Data as Guild); break; case GatewayDispatchType.GuildDelete: GuildDelete?.Invoke(evnt.Data as UnavailableGuild); break; case GatewayDispatchType.ChannelCreate: ChannelCreate?.Invoke(evnt.Data as Channel); break; case GatewayDispatchType.ChannelUpdate: ChannelUpdate?.Invoke(evnt.Data as Channel); break; case GatewayDispatchType.ChannelDelete: ChannelDelete?.Invoke(evnt.Data as Channel); break; case GatewayDispatchType.ChannelPinsUpdate: ChannelPinsUpdate?.Invoke(evnt.Data as ChannelPinsUpdateEvent); break; case GatewayDispatchType.GuildMemberAdd: GuildMemberAdd?.Invoke(evnt.Data as GuildMemberAddEvent); break; case GatewayDispatchType.GuildMemberUpdate: GuildMemberUpdate?.Invoke(evnt.Data as GuildMemberUpdateEvent); break; case GatewayDispatchType.GuildMemberRemove: GuildMemberRemove?.Invoke(evnt.Data as GuildMemberRemoveEvent); break; case GatewayDispatchType.GuildMembersChunk: GuildMembersChunk?.Invoke(evnt.Data as GuildMembersChunkEvent); break; case GatewayDispatchType.GuildRoleCreate: GuildRoleCreate?.Invoke(evnt.Data as GuildRoleCreateEvent); break; case GatewayDispatchType.GuildRoleUpdate: GuildRoleUpdate?.Invoke(evnt.Data as GuildRoleUpdateEvent); break; case GatewayDispatchType.GuildRoleDelete: GuildRoleDelete?.Invoke(evnt.Data as GuildRoleDeleteEvent); break; case GatewayDispatchType.GuildBanAdd: GuildBanAdd?.Invoke(evnt.Data as GuildBanAddEvent); break; case GatewayDispatchType.GuildBanRemove: GuildBanRemove?.Invoke(evnt.Data as GuildBanRemoveEvent); break; case GatewayDispatchType.GuildEmojisUpdate: GuildEmojisUpdate?.Invoke(evnt.Data as GuildEmojiUpdateEvent); break; case GatewayDispatchType.GuildIntegrationsUpdate: GuildIntegrationsUpdate?.Invoke(evnt.Data as GuildIntegrationsUpdateEvent); break; case GatewayDispatchType.MessageCreate: MessageCreate?.Invoke(evnt.Data as Message); break; case GatewayDispatchType.MessageUpdate: MessageUpdate?.Invoke(evnt.Data as Message); break; case GatewayDispatchType.MessageDelete: MessageDelete?.Invoke(evnt.Data as MessageDeleteEvent); break; case GatewayDispatchType.MessageDeleteBulk: MessageDeleteBulk?.Invoke(evnt.Data as MessageDeleteBulkEvent); break; case GatewayDispatchType.MessageReactionAdd: MessageReactionAdd?.Invoke(evnt.Data as MessageReactionAddEvent); break; case GatewayDispatchType.MessageReactionRemove: MessageReactionRemove?.Invoke(evnt.Data as MessageReactionRemoveEvent); break; case GatewayDispatchType.MessageReactionRemoveAll: MessageReactionRemoveAll?.Invoke(evnt.Data as MessageReactionRemoveAllEvent); break; case GatewayDispatchType.PresenceUpdate: PresenceUpdate?.Invoke(evnt.Data as Presence); break; case GatewayDispatchType.UserUpdate: UserUpdate?.Invoke(evnt.Data as User); break; case GatewayDispatchType.TypingStart: TypingStart?.Invoke(evnt.Data as TypingStartEvent); break; case GatewayDispatchType.VoiceStateUpdate: VoiceStateUpdate?.Invoke(evnt.Data as VoiceState); break; case GatewayDispatchType.VoiceServerUpdate: VoiceServerUpdate?.Invoke(evnt.Data as VoiceServerUpdateEvent); break; case GatewayDispatchType.WebhooksUpdate: WebhooksUpdate?.Invoke(evnt.Data as WebhooksUpdateEvent); break; } }