Skip to content
Advertisement

Cooldowns, reactions and few more problems with discord.py

Im creating a discord bot in python and i have few problems i would like to get a help with.

1. I would like to know how to add cooldown on a command. So for example someone will use a command and everyone will not be able to use the same command for some amount of time.

Here is one of my commands, i tried using time module at the end of the code, it works but you are not able to use any other commands. Any advice ?

JavaScript

2. Second problem is similiar to the first one, but instead of adding cooldown on a command. I would like to add cooldown on a question.

Here is my code on a question and i want to add cooldown so people will try to answer the question but they will be able to do it only, lets say, for 30 seconds, then the question will just end if nobody had answered it.

JavaScript

3. The third one is kinda tricky, its about that bot would be able to add reactions on its own message.

Here you can see a picture how it should looks like. I want the bot to add reactions on its own message and then if there is any method when someone click on A, something happens.

enter image description here

4. And the last problem is quite simple.

Here we can take the same code from the first problem. To execute this command, people must write Who but i want to make that people can also write wHo, whO, WHo and so on regardless on uppercases or lowercases.

JavaScript

Advertisement

Answer

  1. discord.py has a built-in support for cooldowns, here an example
JavaScript
  1. This question is kinda tricky, you’d need to use a cog and commands.CooldownMapping (There’s no docs about it so I can’t give you the link)
JavaScript

(This was heavily inspired by one of my previous answers)

  1. This question is a really easy one, simply use Message.add_reaction method
JavaScript

Note: For default reactions the reaction must be a unicode, to get it :emoji:

  1. You can use the str.lower method
JavaScript
JavaScript

If you’re using discord.Client none of this is gonna work, you need to use commands.Bot

Reference:

I answered your questions cause I know the answer to all of them, next time try to separate each question and focus more on each of them, what have you tried, what is the result, what is the expected result…

Advertisement