F
F
F1azy2022-02-19 09:27:35
Python
F1azy, 2022-02-19 09:27:35

Why, when I want to mute a player, I write, for example, “-mute @F1azy 1 test”, the message about the player's mute is sent only after the mute has passed?

I also want to make the mute be issued for a while, but I don’t know how to do it
Here is the code itself:

@bot.command(pass_context=True)
@commands.has_permissions(administrator=True)
async def mute(ctx, member: discord.Member, time: int, reason):
channel = bot.get_channel(939121803324981275)
muterole = discord.utils.get(ctx.guild.roles, id = 942028190715617340)
emb = discord.Embed(color=344462)
emb.add_field(name=" ✅ Muted", value='User {} has been muted!'.format(member.mention))
emb.add_field(name="Moderator", value = ctx.message.author.mention, inline = False)
emb.add_field( name="Reason", value = reason, inline = False)
await member.add_roles(muterole)
await asyncio.sleep(time * 60)
await member.remove_roles(muterole)
await channel.send(embed = emb)

@bot.command(pass_context=True)
@commands.has_permissions(administrator=True)
async def unswitch(ctx, member : discord.Member):
channel = bot.get_channel(939121803324981275)
muterole = discord.utils.get(ctx.guild.roles, id = 942028190715617340)
emb = discord.Embed(color=344462)
emb.add_field(name="✅ UnMuted", value='User {} has been muted!'.format(member.mention))
emb.add_field(name="Moderator", value = ctx.message.author.mention, inline = False)
await member.remove_roles( muterole)
await channel.send(embed = emb)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
wz, 2022-02-19
@rensly

1. This is how discord works.
2. You can make a delay using asyncio.sleep() (in seconds)

V
Vindicar, 2022-02-19
@Vindicar

Because you ordered the bot to do just that.

await member.add_roles(muterole) # добавляешь роль
await asyncio.sleep(time * 60) # ЖДЕШЬ
await member.remove_roles(muterole) # удаляешь роль
await channel.send(embed = emb) #отправляешь сообщение

He does what he says.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question