Timeout? #5
Timeout?
#5
-
|
How to set timeouts for users attempting to run bot commands? |
Beta Was this translation helpful? Give feedback.
Answered by
q31r
Mar 17, 2024
Replies: 2 comments 2 replies
-
I mean in a way to prevent users spamming the bot commands in chat |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
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, you can ask in {DISCORD_QA_CHANNEL} or create a ticket at {DISCORD_TICKET_CHANNEL} and one of our staff members will reply as soon as possible!"
await ctx.send(response_message) |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
Elliot01Sepiol
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 ;)