public async Task ReactionAdded(Cacheable <IUserMessage, ulong> message, ISocketMessageChannel channel, SocketReaction reaction, CancellationToken token) { if (channel.Name != "verification") { return; } var guild = _discordClient.GetEstrangedGuild(); // The "verified" role var role = guild.GetRole(845401897204580412); var user = await _discordClient.Rest.GetGuildUserAsync(guild.Id, reaction.UserId); if (user.RoleIds.Contains(role.Id)) { _logger.LogWarning("User {User} already has role {Role}", user, role); return; } _logger.LogInformation("Adding role {Role} to {User}", role, user); await user.AddRoleAsync(role); user = await _discordClient.Rest.GetGuildUserAsync(guild.Id, reaction.UserId); _logger.LogInformation("{User} now has roles {Roles}", user, string.Join(", ", user.RoleIds.Select(guild.GetRole).Select(x => x.Name))); }
public async Task UserJoined(SocketGuildUser user, CancellationToken token) { _logger.LogInformation("User joined: {0}", user); var guild = _discordClient.GetEstrangedGuild(); var welcomeChannel = guild.TextChannels.Single(x => x.Name == "welcome"); var rulesChannel = guild.TextChannels.Single(x => x.Name == "rules"); var welcome = $"Welcome to the Estranged Discord server <@{user.Id}>! " + $"See <#{rulesChannel.Id}> for the server rules, you might also be interested in these channels:"; var interestingChannels = string.Join("\n", new[] { $"* <#437311972917248022> - Estranged: Act I discussion", $"* <#437312012603752458> - Estranged: The Departure discussion", $"* <#439742315016486922> - Work in progress development screenshots" }); var moderators = guild.Roles.Single(x => x.Name == "moderators") .Members.Where(x => !x.IsBot) .OrderBy(x => x.Nickname) .Select(x => $"<@{x.Id}>"); var moderatorList = $"Your moderators are {string.Join(", ", moderators)}."; await welcomeChannel.SendMessageAsync($"{welcome}\n{interestingChannels}\n{moderatorList}", options : token.ToRequestOptions()); }
public static SocketTextChannel GetChannelByName(this DiscordSocketClient client, string channelName) { return(client.GetEstrangedGuild().TextChannels.Single(x => x.Name == channelName)); }