#cooldown command

1 messages · Page 1 of 1 (latest)

hazy cradle
#
       private static readonly ConcurrentDictionary<ulong, DateTimeOffset> CommandExecutionTimestamps = new();

        [SlashCommand("example", "?")]
        public async Task ExampleCommand()
        {
            if (CommandExecutionTimestamps.TryGetValue(Context.User.Id, out var lastExecution) &&
                (DateTimeOffset.Now - lastExecution) < TimeSpan.FromSeconds(5))
            {
                await RespondAsync("Timeout", ephemeral: true);
                return;
            }
            
            await RespondAsync("Hello", ephemeral: true);
            CommandExecutionTimestamps[Context.User.Id] = DateTimeOffset.Now;
        }
#

someone on the discord api server helped me