Пример #1
0
        private async Task WriteMessageToDiscord(ShowChatLogModel data)
        {
            var settings = _featuredChatConnections.Where(x => x.Channel == data.ChannelId);

            foreach (var setting in settings)
            {
                await CreateMessageAsync(ulong.Parse(setting.Settings.GuildId), ulong.Parse(setting.Settings.ChannelId), data);
            }
        }
Пример #2
0
        private async Task <ulong> CreateMessageAsync(ulong guildId, ulong channelId, ShowChatLogModel data)
        {
            foreach (var instance in _botDiscordSocketClients)
            {
                if (instance.Guilds.Any(x => x.Id == guildId))
                {
                    try
                    {
                        SocketTextChannel currentChannel = instance.GetChannel(channelId) as SocketTextChannel;


                        var embed = new EmbedBuilder()
                                    .WithTitle($"{data.User.DisplayName}")
                                    .WithDescription($"{data.Message.Body}")
                                    .WithThumbnailUrl($"{data.User.ProfileImageUrl}?_={Guid.NewGuid()}")
                                    .Build();

                        var message = await currentChannel.SendMessageAsync(embed : embed);

                        return(message.Id);
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError(ex, $"FeaturedChatService.CreateMessageAsync");
                    }
                }
            }
            return(0);
        }