Как создать функцию в команде (discord.py), которая позволяет использовать команду только раз в минуту? - PullRequest
0 голосов
/ 22 апреля 2020

Как создать функцию в команде (discord.py), которая позволяет использовать команду только раз в минуту? это часть моего кода, которую я хотел бы рассчитать по времени:

@bot.command()
async def busk(ctx):
        member = ctx.message.author.id #gets the user ID, which i use as the _id in pymongo because everyones is different.
        results1 = collection.find_one({"_id": member})#checks if their account exists
        results = collection.find({"_id": member})#opens to their 'account'
        if results1 == None: #if their account does not exist
                post = {"_id": member, "coins": 0} #create an account with their member ID as the _id
                collection.insert_one(post)#inserts the document(account) to the database.
                await ctx.send("You did not have an account, so we created one for you! try running this command again.")
        else:#If they do have an account:
                for result in results:
                        randomdonation = random.choice([1,2,1,'none',1,'none',10,'none',10,12,11,'none',11,'none',14,25,15,'none',15,13,13,12,18,'none',18,19,20,21,21,2,2,100,3,4,5,14,14])#random choices, selected from an array so I can choose which commonly pop up.
                        if randomdonation == "none":#if they get the choice 'none'
                                await ctx.send("srry u get " + randomdonation)
                        else:
                                db.testing.update_one({"_id": member}, {'$inc': {"coins": randomdonation}})
                                await ctx.send(str(randomdonation) + " Coins were added to your bank!")

это команда, которую я хотел бы рассчитать по времени, и я попытался использовать time.sleep (), но он просто спит весь бот .

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...