<tfoot id='1qgl6'></tfoot>

    <small id='1qgl6'></small><noframes id='1qgl6'>

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

        <bdo id='1qgl6'></bdo><ul id='1qgl6'></ul>
      <legend id='1qgl6'><style id='1qgl6'><dir id='1qgl6'><q id='1qgl6'></q></dir></style></legend>

      1. 我的 TEMPMUTE 命令出现一定错误

        时间:2023-10-11
          <bdo id='hVDlz'></bdo><ul id='hVDlz'></ul>
          <legend id='hVDlz'><style id='hVDlz'><dir id='hVDlz'><q id='hVDlz'></q></dir></style></legend>

            • <tfoot id='hVDlz'></tfoot>

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

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

                • 本文介绍了我的 TEMPMUTE 命令出现一定错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我已经制作了一个临时代码,或者我们可以说我在 stackoverflow 上找到了一个.我复制了代码,但它似乎不起作用.如果你们中的任何人现在可以帮助我,谢谢!代码是;

                  I have made a tempmute code or we can say I found one on stackoverflow. I copied the code but it doesn't seem to work. If anyone of you now and can help me thanks! The code is;

                  @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'
                      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.send(embed=tempmuteembed)
                  
                   
                      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.ext.commands.errors.BadArgument: Converting to "int" failed for parameter "time".
                  

                  推荐答案

                  这是因为 CommandConverters 在其参数上运行.由于 time 默认为 0,其类型为 int,因此库尝试将 time 转换为 >int.但是,如果您提供像 10m 这样的单位后缀,则此转换将失败,因为 int('10m') 失败并出现 ValueError,其中轮到提出 BadArgument.

                  This is because Commands have Converters that are run on their arguments. Since time defaults to 0, which is of type int, the library tries to convert time to an int. However, this conversion will fail if you give a unit suffix like 10m, since int('10m') fails with a ValueError, which in turn raises BadArgument.

                  要解决这个问题,只需在 time 参数中添加适当的类型注释:

                  To fix this, simply add a proper type annotation to your time parameter:

                  from typing import Union
                  async def tempmute(ctx, member: discord.Member, time: Union[int, str] = 0, reason=None):
                  

                  这篇关于我的 TEMPMUTE 命令出现一定错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何使数据在 discord.py 中以表格形式显示? 下一篇:前缀和非前缀命令在 python discord bot 上不能一起工

                  相关文章

                  最新文章

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

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

                • <legend id='SAfsR'><style id='SAfsR'><dir id='SAfsR'><q id='SAfsR'></q></dir></style></legend>

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