コード例 #1
0
        public async Task ShowWarning(
            CommandContext ctx,
            [Description("Warning id to show.")] int id
            )
        {
            await ctx.TriggerTypingAsync();

            Warning?warning = await _warningService.GetWarningAsync(id);

            if (warning == null)
            {
                try
                {
                    await ctx.Channel.SendMessageAsync("Varování s tímto ID neexistuje.");
                }
                catch (Exception e)
                {
                    _logger.LogWarning(e, "Couldn't send a message");
                }

                return;
            }

            try
            {
                DiscordMember warningMember = await ctx.Guild.GetMemberAsync(warning.UserId);

                await ctx.Channel.SendMessageAsync(
                    $"**Varování {warning.Id}** pro uživatele **{warningMember.RatherNicknameThanUsername()}**:\n" +
                    $"{warning.Reason.RemoveDiscordMentions(ctx.Guild, _logger)}");

                await ctx.Message.CreateReactionAsync(DiscordEmoji.FromName(ctx.Client, ":+1:"));
            }
            catch (Exception e)
            {
                _logger.LogWarning(e, "Couldn't send warning message");
                await ctx.Message.CreateReactionAsync(DiscordEmoji.FromName(ctx.Client, ":-1:"));
            }
        }