/// <summary> /// Called each new message from Discord /// </summary> private async Task OnMessageCreated(DiscordClient client, MessageCreateEventArgs e) { if (_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Trace)) { _logger.LogTrace(@"Message from {author}"); } if (e.Message.Author.IsBot || IsThisMessageForTheBot(e) == false) { return; // Ignore all botusers or messages not for the bot } // var members = await e.Guild.GetAllMembersAsync(); // Get the member info and roles // var member = members.Where(n => n.Id == e.Message.Author.Id).FirstOrDefault(); DiscordMember member = (DiscordMember)e.Message.Author; var roles = member.Roles.Select(n => n.Name).ToList(); var parser = new BotParser( e.Message.Content, e.Message.MentionedUsers.Where(n => n.IsBot == true).Count() > 0, roles, member.IsOwner, e.Author.Username ); var responseMessage = await _botRunner.HandleMessage(parser); var embed = new DiscordEmbedBuilder { Color = new DiscordColor("#550099"), Title = responseMessage.Title, Description = (responseMessage.Text.Length < 2048) ? responseMessage.Text : responseMessage.Text[..2048]
/// <summary> /// Called each new message from Discord /// </summary> private async Task OnMessageCreated(MessageCreateEventArgs e) { if (_logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Trace)) { _logger.LogTrace(@"Message from {author}"); } if (e.Message.Author.IsBot || IsThisMessageForTheBot(e) == false) { return; // Ignore all botusers or messages not for the bot } var parser = new BotParser(e.Message.Content, e.Message.MentionedUsers.Where(n => n.IsBot == true).Count() > 0); var responseMessage = await _botRunner.HandleMessage(parser); await e.Message.RespondAsync(responseMessage); }