Skip to content
Discussion options

You must be logged in to vote

This function sets a cooldown of 5 seconds for users to prevent spamming the commands (!help command for example in here). If the user tries to use the command within the cooldown period, their message will be deleted ;)

cooldowns = {} 
def check_cooldown(ctx):
  now = time.time()
  user_id = ctx.author.id
  if user_id in cooldowns and cooldowns[user_id] > now:
    return False
  cooldowns[user_id] = now + 5 
  return True

@client.command()
async def help(ctx):
  if not check_cooldown(ctx):
    await ctx.message.delete()
    return
  else:
    response_message = f"Hi <@{ctx.author.id}>, {SERVER_NAME} bot is here! If you have any questions/issues related to the Minecraft or Discord Server…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@Elliot01Sepiol
Comment options

@q31r
Comment options

q31r Mar 17, 2024
Maintainer

Answer selected by Elliot01Sepiol
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
enhancement New feature or request question Further information is requested
2 participants