I
I
Igor Gafarchik2020-05-13 21:03:59
Python
Igor Gafarchik, 2020-05-13 21:03:59

Discord.py sleep per function?

Good day forum users!
There is a ds bot in python. Added the function of mute and auto unmute.

@bot.command(pass_context=True)
@commands.has_permissions(administrator = True)
async def user_mute(ctx,member:discord.Member):
    await ctx.channel.purge(limit = 1)
    mute_role = discord.utils.get(ctx.message.guild.roles,name = 'mute')
    await member.add_roles(mute_role)
    await ctx.send(f'{member.mention} получил мут за плохое поведение!')
    time.sleep(30)
    unmute = discord.utils.get(ctx.message.guild.roles,name = 'mute')
    await member.remove_roles(unmute)

here is some code. But sleep stops all the code. How can I stop only this function so that the rest can continue its work? Is this even possible?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Deleting Account, 2020-05-13
@Gafarchik

import asyncio

asyns def():
         ...
         await asyncio.sleep(30)
         ....

Did it help?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question