Answer the question
In order to leave comments, you need to log in
How to make a tempmute discord.py command?
How to make it possible to mute not by seconds, but by minutes / hours / days,
here is the code:
@bot.command(pass_context=True)
@commands.has_permissions(administrator=True)
async def mute(ctx, member: discord.Member, time=0, *, reason=None):
emb = discord.Embed(title=" ", colour=discord.Color.blue())
await ctx.channel.purge(limit=1)
author = ctx.message.author
emb.set_author(name=f"{member} was Zamyuten!", icon_url=member. avatar_url)
emb.set_footer(text=f"Muted: {author}\nReason: {reason}\nSeconds: {time}", icon_url=ctx.author.avatar_url)
await ctx.send(embed=emb)
muted_role = discord.utils.get(ctx.message.guild.roles, name="Muted")
await member.add_roles(muted_role)
if time == None:
await ctx.send("Time: Forever")
elif reason == None:
await ctx.send("Reason: not specified")
await asyncio.sleep(time)
await member.remove_roles(muted_role)
await ctx.channel.purge(limit=1)
await ctx.send(f" {member.mention} role muted\nElapsed: {time} seconds")
Answer the question
In order to leave comments, you need to log in
First, I advise you to familiarize yourself with a newer version of the library on which you write and understand that pass_context=True have not been used for a long time.
Secondly: if you want to issue a mute for a certain amount of time, then you need to use a database and various cycles so that after a given time the bot removes the mute. At least the function should not have time=0 , but time: int = None
Fortunately for you, the Discord developers have done everything for you and now you can write a similar function very quickly.
Take this video as an example, even without knowing English everything is very clear when watching - https://youtu.be/W2TcxVNctw8
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question