A
A
Andrew2021-01-30 14:49:55
Python
Andrew, 2021-01-30 14:49:55

How to ban / mute for a while in (m, h, d, y)?

Hello, I already have a code for a temporary ban, but I would like it to be possible to add to the time, for example,
m - minutes, h - hours, d - days and y - years, and it probably won’t hurt to place simple letters in embed enter the same minutes, days, etc. how can I do it?

@client.command()
@commands.has_permissions(administrator=True)
async def mute(ctx, member: discord.Member, time: int, reason = 'Не указана'):
    emb = discord.Embed(title=f'У игрока {member.name} Был заблокирован чат!', colour=0x9900FF)
    await ctx.channel.purge(limit=1)
    mute_role = discord.utils.get(ctx.guild.roles, name = 'Muted')
    await member.add_roles(mute_role)
    emb.set_author(name = member.name, icon_url=member.avatar_url)
    emb.add_field(name = f'На {time}', value=f'Причина: {reason}')
    await ctx.send(embed=emb)
    await asyncio.sleep(time * 60) #Вот тут функция разбана через время
    await member.remove_roles(mute_role)
    node = discord.Embed(title=f'У игрока {member.name} Был разблокирован чат!', colour=0x9900FF)
    node.set_author(name = member.name, icon_url=member.avatar_url)
    await ctx.send(embed=node)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
shurshur, 2021-01-30
@Mikyc

Somehow you can:

def time_seconds(time: str) -> int:
  if time.endswith('d'):
    return int(time[:-1])*86400
  elif time.endswith('h'):
    return int(time[:-1])*3600
  elif time.endswith('m'):
    return int(time[:-1])*60
  elif time.endswith('s'):
    return int(time[:-1])
  else:
    return int(time)

for t in ['3d','6h','9m','12s','15']:
  s = time_seconds(t)
  print (f"{t} -> {s}")

The same and even more can be done using the timeparse module

A
Anton Teploukhov, 2018-07-26
@thechucky

very similar to "Celtic MN", but I had a different nameceltic-mn-upper.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question