DSharpPlus icon indicating copy to clipboard operation
DSharpPlus copied to clipboard

Slash Commands Cooldown

Open hopto-dot opened this issue 3 years ago • 11 comments

I've been wanting to implement a cool down for slash commands but from the DSharp​Plus.​Slash​Commands.​Attributes page in the docs it doesn't seem like it exists - are cooldown attributes not able to be implemented for slash commands or is this just a missing feature?

What's the recommended way to implement per-user cooldowns without a slash command attribute?

hopto-dot avatar Aug 10 '22 08:08 hopto-dot

You may use TimeSpan Class to implement the per-user cooldowns.

Poinet avatar Aug 10 '22 11:08 Poinet

To be honest, the DSharpPlus does not need to implement per-user cooldown attribute for Slash Commands, you may create your own attribute instead.

Poinet avatar Aug 10 '22 11:08 Poinet

while that is a good point, DSharpPlus does provide a cooldown attribute in CommandsNext, so a SlashCommands cooldown attribute isn't unjustified per se.

akiraveliara avatar Aug 10 '22 12:08 akiraveliara

You may use TimeSpan Class to implement the per-user cooldowns. To be honest, the DSharpPlus does not need to implement per-user cooldown attribute for Slash Commands, you may create your own attribute instead.

@Poinet I'm still an unskilled programmer, would you mind elaborating?

I was thinking something like creating a MemberUse class which inherits from DiscordMember with a property that stores when the user last used a command. When a command is used they would be added to a list called usersUsingCommand and removed once the command has finished executing. The problem I see with doing this is that an instance of MemberUse in the list won't be removed if code halts unexpectedly. This is why I'm really wanting a cooldown attribute because it makes it super easy and deals with this all for me.

hopto-dot avatar Aug 10 '22 18:08 hopto-dot

If you need a reference for implementation, see https://github.com/DSharpPlus/DSharpPlus/blob/master/DSharpPlus.CommandsNext/Attributes/CooldownAttribute.cs.

akiraveliara avatar Aug 10 '22 18:08 akiraveliara

I'm going to have to do it another way because that is beyond my level.

hopto-dot avatar Aug 10 '22 19:08 hopto-dot

fortunately for you, #1375 aims to port the feature to slash commands.

akiraveliara avatar Aug 10 '22 19:08 akiraveliara

Wow, that's great! Can I expect this to be out in a nightly release sometime soon?

hopto-dot avatar Aug 10 '22 19:08 hopto-dot

Probably as soon as someone gets around to testing it.

akiraveliara avatar Aug 10 '22 19:08 akiraveliara

Nightlies are created when a new commit to the master branch happens. They're done automatically by Github Actions and are usually downloadable from Nuget within 10 minutes

OoLunar avatar Aug 10 '22 19:08 OoLunar

Thank you guys, much appreciated 👍

hopto-dot avatar Aug 10 '22 19:08 hopto-dot