private async Task Discord_GuildAvailable(SocketGuild guild) { logger.LogInformation("Connected to {guildId} {guildName}", guild.Id, guild.Name); if (guild.Id == appOptions.ServerId) { cts?.Cancel(); cts = new CancellationTokenSource(); var token = cts.Token; var channel = guild.GetVoiceChannel(appOptions.ChannelId); if (channel != null) { await SetNicknameAsync(guild); logger.LogInformation("Start loop on channel {channelId} {channelName} of {guildName}", appOptions.ChannelId, channel.Name, guild.Name); Task.Run(async() => { await PlayLoopAsync(channel, token); }); } else { logger.LogError("Cannot find channel {channelId}", appOptions.ChannelId); } } }
public async Task OnGuildReady(SocketGuild guild) { if (guild.CurrentUser.VoiceChannel != null && guild.VoiceChannels.Count > 1) { // seems like the bot died during VC, this'll cause issue such as the bot being slient and stuffs so let's force it out Log.Information("Seems like the bot died while in a voice chat, forcing disconnect..."); await audioService.JoinVoiceChannel(guild, guild.CurrentUser.VoiceChannel); await audioService.LeaveVoiceChannel(guild); Log.Information($"Successfully disconnected the bot from the VC in {guild.Id}!"); } // shhhh this is not a proper fix, i'm aware await Task.Delay(200); if (RossConfig.Root.Binding.BindedChannel > 0 && RossConfig.Root.Binding.BindedServer == guild.Id) { Binding bindingConfig = RossConfig.Root.Binding; Log.Information($"Joining {bindingConfig.BindedChannel} in {guild.Id} due to binding."); SocketVoiceChannel voiceChannel = guild.GetVoiceChannel(RossConfig.Root.Binding.BindedChannel); await audioService.JoinVoiceChannel(guild, voiceChannel); var playlist = audioService.GetPlaylist(guild); playlist.AddFromPlaylistDirectory(RossConfig.Root.Binding.PlaylistName); playlist.Loop = bindingConfig.Loop; await Task.Run(() => playlist.StartPlaylist(audioService, guild, this.client)).ConfigureAwait(false); } }
public Task InitAsync() { guild = _discord.GetGuild(ulong.Parse(_config["guild"])); channel = guild.GetVoiceChannel(ulong.Parse(_config["channel"])); return(Task.CompletedTask); }
private async Task Discord_GuildAvailable(SocketGuild guild) { logger.LogInformation("Connected to {guildId} {guildName}", guild.Id, guild.Name); if (guild.Id == appOptions.ServerId) { cts?.Cancel(); cts = new CancellationTokenSource(); var token = cts.Token; var channel = guild.GetVoiceChannel(appOptions.ChannelId); try { if (!string.IsNullOrWhiteSpace(appOptions.Nickname)) { if (guild.CurrentUser.Nickname != appOptions.Nickname) { logger.LogInformation("Changing nickname to {nickname}", appOptions.Nickname); await guild.CurrentUser.ModifyAsync(props => { props.Nickname = appOptions.Nickname; }); } } else { if (guild.CurrentUser != null) { logger.LogInformation("Clear nickname"); await guild.CurrentUser.ModifyAsync(props => { props.Nickname = appOptions.Nickname; }); } } } catch (Exception ex) { logger.LogError(ex, "Cannot change nick name to {nickname} in guild {guildName}", appOptions.Nickname, guild.Name); } if (channel != null) { logger.LogInformation("Start loop on channel {channelId}", appOptions.ChannelId); Task.Run(async() => { await PlayLoopAsync(channel, token); }); } else { logger.LogError("Cannot find channel {channelId}", appOptions.ChannelId); } } }
private Task client_UserVoiceStateUpdated(SocketUser arg1, SocketVoiceState arg2, SocketVoiceState arg3) { if (m_guild != null && arg3.VoiceChannel != null && m_guild.GetVoiceChannel(arg3.VoiceChannel.Id) != null && !arg1.IsBot) { SocketVoiceConnection arg = new SocketVoiceConnection(arg1, arg2, arg3); return(InvokeEvent <SocketVoiceConnection>(DiscordEventType.VoiceStateUpdated, arg)); } return(Task.CompletedTask); }
public bool ConnectToVoice(ISocketMessageChannel requester, string channelName = "") { SocketVoiceChannel channel = m_guild.GetVoiceChannel(channelName); if (channel == null) { Logging.LogError(LogType.Bot, $"Channel name {channelName} not on server {m_guild.Name}."); return(false); } return(ConnectToVoice(requester, channel)); }
private Task Client_GuildAvailable(SocketGuild guild) { if (Config.GuildConfigs.TryGetValue(guild.Id, out var guildConfig) && guildConfig.AutoConnect) { var vChannel = guild.GetVoiceChannel(guildConfig.VoiceChannelId); var msgChannel = guild.GetTextChannel(guildConfig.MessageChannelId); if (vChannel != null && msgChannel != null) { Task.Run(() => JoinAudio(guild, msgChannel, vChannel).ConfigureAwait(false)); } } return(Task.CompletedTask); }
private async Task Client_GuildAvailable(SocketGuild guild) { var guildConfig = await Config.GetConfigForGuildAsync(guild); if (guildConfig != null && guildConfig.AutoConnect) { var vChannel = guild.GetVoiceChannel(guildConfig.VoiceChannelId); var msgChannel = guild.GetTextChannel(guildConfig.MessageChannelId); if (vChannel != null && msgChannel != null) { _ = Task.Run(() => JoinAudio(guild, msgChannel, vChannel).ConfigureAwait(false)); } } }
public static IAudioClient ConnectToVoice(this SocketGuild guild, string channel) { var voiceChannel = guild.GetVoiceChannel(channel); if (voiceChannel == null) { string channelName = string.IsNullOrEmpty(channel) ? "FirstOrDefault" : channel; Logging.LogError(LogType.Bot, $"Failed to find voice channel {channelName} in server {guild.Name}"); return(null); } else { return(ConnectToVoice(guild, voiceChannel)); } }
// Because Discord does not automatically unmute someone after they've been given speaking rights. private static async void UpdateVoiceChannel(SocketGuild guild) { var g = Configuration.Config.Guilds.First(x => x.SocketGuildId == guild.Id); if (!guild.Users.First(x => x.Id == g.LastHatId).Roles.Contains(guild.GetRole(g.MutedRoleId))) { return; } var channel = guild.Users.First(x => x.Id == g.LastHatId).VoiceChannel; if (channel == null) { return; } await guild.Users.First(x => x.Id == g.LastHatId) .ModifyAsync(x => x.Channel = guild.GetVoiceChannel(g.AfkVoiceChannelId)); await guild.Users.First(x => x.Id == g.LastHatId).ModifyAsync(x => x.Channel = channel); }
public async Task ChangeVoiceChannel(SocketUser user, SocketVoiceState beforeState, SocketVoiceState afterState) { SocketGuild guild = afterState.VoiceChannel?.Guild; if (guild == null) { guild = beforeState.VoiceChannel.Guild; } SocketGuildUser guildUser = guild.GetUser(user.Id); SocketVoiceChannel afkChannel = guild.GetVoiceChannel(Program.serverConfig.afkChannel); if (guildUser.VoiceState == null) { return; } if (guildUser.VoiceState.Value.IsSelfDeafened && Program.serverConfig.whiteList.All(x => x != user.Id) && !afterState.VoiceChannel.Equals(afkChannel)) // Moves self muted users to afk channel { if (afkChannel != null) { await guildUser.ModifyAsync(x => x.Channel = afkChannel); var rnd = new Random().Next(0, 101); if (rnd > 99) { var rng = new Random().Next(0, rareMsges.Count()); await guildUser.SendMessageAsync(rareMsges[rng]); } else { var rng = new Random().Next(0, msges.Count()); await guildUser.SendMessageAsync(msges[rng]); } } } }
private Task ReadyAsync() { ShowMessage(); #region Testing Server GeneralChannel = _client.GetGuild(_GET_server).GetTextChannel(_general); BotChannel = _client.GetGuild(_GET_server).GetTextChannel(_bot); ErrorChannel = _client.GetGuild(_GET_server).GetTextChannel(_errors); StartItGeneralTextChannel = _client.GetGuild(_serverName).GetTextChannel(_startIT_general); StartItGeneralVoiceChannel = _client.GetGuild(_serverName).GetVoiceChannel(_generalVoice); Team1TextChannel = _client.GetGuild(_serverName).GetTextChannel(_team1); Team1VoiceChannel = _client.GetGuild(_serverName).GetVoiceChannel(_team1Voice); Team2TextChannel = _client.GetGuild(_serverName).GetTextChannel(_team2); Team2VoiceChannel = _client.GetGuild(_serverName).GetVoiceChannel(_team2Voice); Guild = _client.GetGuild(_serverName); //Server object #endregion #region GETserver GetServer = _client.GetGuild(_GET_server); // GET server GetServerGeneralChannel = GetServer.GetTextChannel(_GET_general); // General text channel StartIt4Team1TextChannel = GetServer.GetTextChannel(_startIT4_team1); StartIt4Team2TextChannel = GetServer.GetTextChannel(_startIT4_team2); StartIt4Team3TextChannel = GetServer.GetTextChannel(_startIT4_team3); StartIt4Team4TextChannel = GetServer.GetTextChannel(_startIT4_team4); StartIt4Team5TextChannel = GetServer.GetTextChannel(_startIT4_team5); StartIt4Team6TextChannel = GetServer.GetTextChannel(_startIT4_team6); StartIt4Team1VoiceChannel = GetServer.GetVoiceChannel(_startIT4_team1_voice); StartIt4Team2VoiceChannel = GetServer.GetVoiceChannel(_startIT4_team2_voice); StartIt4Team3VoiceChannel = GetServer.GetVoiceChannel(_startIT4_team3_voice); StartIt4Team4VoiceChannel = GetServer.GetVoiceChannel(_startIT4_team4_voice); StartIt4Team5VoiceChannel = GetServer.GetVoiceChannel(_startIT4_team5_voice); StartIt4Team6VoiceChannel = GetServer.GetVoiceChannel(_startIT4_team6_voice); #endregion return(Task.CompletedTask); }
public virtual ISocketVoiceChannelWrapper?GetVoiceChannel(ulong id) { var rawChannel = _socketGuild.GetVoiceChannel(id); return(rawChannel != null ? new SocketVoiceChannelWrapper(rawChannel) : null); }