<small id='4OB0p'></small><noframes id='4OB0p'>

      • <bdo id='4OB0p'></bdo><ul id='4OB0p'></ul>
      <tfoot id='4OB0p'></tfoot>

    1. <i id='4OB0p'><tr id='4OB0p'><dt id='4OB0p'><q id='4OB0p'><span id='4OB0p'><b id='4OB0p'><form id='4OB0p'><ins id='4OB0p'></ins><ul id='4OB0p'></ul><sub id='4OB0p'></sub></form><legend id='4OB0p'></legend><bdo id='4OB0p'><pre id='4OB0p'><center id='4OB0p'></center></pre></bdo></b><th id='4OB0p'></th></span></q></dt></tr></i><div id='4OB0p'><tfoot id='4OB0p'></tfoot><dl id='4OB0p'><fieldset id='4OB0p'></fieldset></dl></div>

        <legend id='4OB0p'><style id='4OB0p'><dir id='4OB0p'><q id='4OB0p'></q></dir></style></legend>
      1. 在 discord.py 中转换时间的 Tempmute 命令

        时间:2023-09-10

          <legend id='Bk2lz'><style id='Bk2lz'><dir id='Bk2lz'><q id='Bk2lz'></q></dir></style></legend>

            <tbody id='Bk2lz'></tbody>

          <small id='Bk2lz'></small><noframes id='Bk2lz'>

          • <i id='Bk2lz'><tr id='Bk2lz'><dt id='Bk2lz'><q id='Bk2lz'><span id='Bk2lz'><b id='Bk2lz'><form id='Bk2lz'><ins id='Bk2lz'></ins><ul id='Bk2lz'></ul><sub id='Bk2lz'></sub></form><legend id='Bk2lz'></legend><bdo id='Bk2lz'><pre id='Bk2lz'><center id='Bk2lz'></center></pre></bdo></b><th id='Bk2lz'></th></span></q></dt></tr></i><div id='Bk2lz'><tfoot id='Bk2lz'></tfoot><dl id='Bk2lz'><fieldset id='Bk2lz'></fieldset></dl></div>
              <bdo id='Bk2lz'></bdo><ul id='Bk2lz'></ul>
                  <tfoot id='Bk2lz'></tfoot>
                  本文介绍了在 discord.py 中转换时间的 Tempmute 命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想在我的不和谐机器人中进行时间转换.现在,要使用 tempmute 命令,我只需要以秒为单位设置时间,并且我想进行转换,例如1s = 1;1h = 3600 等

                  i want to make something like time convert in my discord bot. Now, to use tempmute command, i need to set time only in seconds, and i want to make converting e.g. 1s = 1; 1h = 3600 etc.

                  回答,我发现了什么,并不能解决我的问题.

                  Answer, what i found, do not solving my problem.

                  这是我的代码:

                  # tempmute
                  @client.command()
                  @commands.has_permissions(kick_members=True)
                  async def tempmute(ctx, member: discord.Member, time=0, reason=None):
                  if not member or time == 0 or time == str:
                      return
                  elif reason == None:
                      reason = 'no reason provided'
                  
                  tempmuteembed = discord.Embed(colour=discord.Colour.from_rgb(0, 255, 0))
                  tempmuteembed.set_author(icon_url=member.avatar_url, name=f'{member} has been tempmuted!')
                  tempmuteembed.set_footer(text=f"{ctx.guild.name}  •  {datetime.strftime(datetime.now(), '%d.%m.%Y at %I:%M %p')}")
                  tempmuteembed.add_field(name=f'ID:', value=f'{member.id}', inline=False)
                  tempmuteembed.add_field(name='Reason:', value=f"{reason}")
                  tempmuteembed.add_field(name='Duration:', value=f"{time}")
                  tempmuteembed.add_field(name=f'By:', value=f'{ctx.author.name}#{ctx.author.discriminator}', inline=False)
                  
                  await ctx.channel.purge(limit=1)
                  
                  guild = ctx.guild
                  for role in guild.roles:
                      if role.name == 'Muted':
                          await member.add_roles(role)
                          await ctx.send(embed=tempmuteembed)
                          await asyncio.sleep(time)
                          await member.remove_roles(role)
                          return
                  

                  推荐答案

                  如果你的输入可能是 15s、20min、1h、2d,你可能的解决方案是:

                  If your input may be 15s, 20min, 1h, 2d, your possible solution is:

                  import re
                  
                  def tempmute(time=0):
                      time_list = re.split('(d+)',time)
                      if time_list[2] == "s":
                          time_in_s = int(time_list[1])
                      if time_list[2] == "min":
                          time_in_s = int(time_list[1]) * 60
                      if time_list[2] == "h":
                          time_in_s = int(time_list[1]) * 60 * 60
                      if time_list[2] == "d":
                          time_in_s = int(time_list[1]) * 60 * 60 * 60
                      return time_in_s
                  
                  
                  print(tempmute("15h"))
                  
                  >>> 54000
                  

                  更新:所以完整的代码应该是这样的.您的 Input 将是一个字符串,如果它不是字符串,则不要返回 None !您输入的格式为 15 分钟、3 秒或 5 小时,否则超时为 0 秒.

                  Update: so the complete code should look something like this. Your Input will be a string, dont return None if its not a string! You input will be in the form of like 15min, 3s or 5h, otherwise the timeout will be 0 seconds.

                  # tempmute
                  @client.command()
                  @commands.has_permissions(kick_members=True)
                  async def tempmute(ctx, member: discord.Member, time=0, reason=None):
                      if not member or time == 0:
                          return
                      elif reason == None:
                          reason = 'no reason provided'
                      try:
                          if time_list[2] == "s":
                              time_in_s = int(time_list[1])
                          if time_list[2] == "min":
                              time_in_s = int(time_list[1]) * 60
                          if time_list[2] == "h":
                              time_in_s = int(time_list[1]) * 60 * 60
                          if time_list[2] == "d":
                              time_in_s = int(time_list[1]) * 60 * 60 * 60
                      except:
                          time_in_s = 0
                   
                      tempmuteembed = discord.Embed(colour=discord.Colour.from_rgb(0, 255, 0))
                      tempmuteembed.set_author(icon_url=member.avatar_url, name=f'{member} has been tempmuted!')
                      tempmuteembed.set_footer(text=f"{ctx.guild.name}  •  {datetime.strftime(datetime.now(), '%d.%m.%Y at %I:%M %p')}")
                      tempmuteembed.add_field(name=f'ID:', value=f'{member.id}', inline=False)
                      tempmuteembed.add_field(name='Reason:', value=f"{reason}")
                      tempmuteembed.add_field(name='Duration:', value=f"{time}")
                      tempmuteembed.add_field(name=f'By:', value=f'{ctx.author.name}#{ctx.author.discriminator}', inline=False)
                   
                      await ctx.channel.purge(limit=1)
                   
                      guild = ctx.guild
                      for role in guild.roles:
                          if role.name == 'Muted':
                              await member.add_roles(role)
                              await ctx.send(embed=tempmuteembed)
                              await asyncio.sleep(time_in_s)
                              await member.remove_roles(role)
                              return
                  

                  这篇关于在 discord.py 中转换时间的 Tempmute 命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何限制 on_message 回复(Discord Python 机器人) 下一篇:引发自定义错误消息

                  相关文章

                  最新文章

                    • <bdo id='KTlr2'></bdo><ul id='KTlr2'></ul>

                    <tfoot id='KTlr2'></tfoot>

                      <legend id='KTlr2'><style id='KTlr2'><dir id='KTlr2'><q id='KTlr2'></q></dir></style></legend>

                      <small id='KTlr2'></small><noframes id='KTlr2'>

                      <i id='KTlr2'><tr id='KTlr2'><dt id='KTlr2'><q id='KTlr2'><span id='KTlr2'><b id='KTlr2'><form id='KTlr2'><ins id='KTlr2'></ins><ul id='KTlr2'></ul><sub id='KTlr2'></sub></form><legend id='KTlr2'></legend><bdo id='KTlr2'><pre id='KTlr2'><center id='KTlr2'></center></pre></bdo></b><th id='KTlr2'></th></span></q></dt></tr></i><div id='KTlr2'><tfoot id='KTlr2'></tfoot><dl id='KTlr2'><fieldset id='KTlr2'></fieldset></dl></div>