コード例 #1
0
        public async Task BanUserAsync([RequireHigherHierarchyPrecondition][EnsureNotSelf] IUser user, [Remainder] string reason = "No reason provided.")
        {
            var time = ParseTimeSpanFromString(ref reason);

            if (string.IsNullOrEmpty(reason))
            {
                reason = "No reason provided.";
            }

            try
            {
                var dmChannel = await user.GetOrCreateDMChannelAsync();

                var embed = new EmbedBuilder()
                {
                    Title = $"You were banned from **{Context.Guild.Name}**",
                    Color = _moderation.GetColorFromInfractionType(InfractionType.Ban)
                }
                .AddField($"Reason", reason, true);

                if (time.TotalMilliseconds > 1000)
                {
                    embed.AddField("Duration", time.Humanize(3, minUnit: TimeUnit.Second));
                }

                await dmChannel.SendMessageAsync("", false, embed.Build());
            }
            catch (Exception)
            {
                await ReplyAsync($"Could not dm user to notify him.");
            }

            var infraction = await _moderation.BanUserFromGuildAsync(user, Context.Guild.Id, Context.User.Id, reason, time, 7);

            if (time.TotalMilliseconds < 1000)
            {
                await ReplyAsync($"#{infraction.Id} | Banned {user.Mention}.");
            }
            else
            {
                await ReplyAsync($"#{infraction.Id} | Banned {user.Mention} for {time.Humanize()}");
            }
        }