• <bdo id='6tVax'></bdo><ul id='6tVax'></ul>
    1. <small id='6tVax'></small><noframes id='6tVax'>

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

        <legend id='6tVax'><style id='6tVax'><dir id='6tVax'><q id='6tVax'></q></dir></style></legend>

        <tfoot id='6tVax'></tfoot>

        有没有办法在我的论点中包含空格?

        时间:2023-10-11
          <tbody id='LWPlV'></tbody>

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

          <tfoot id='LWPlV'></tfoot>

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

                1. 本文介绍了有没有办法在我的论点中包含空格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  在我的 discord 机器人中,我有 2 个命令可以提供和创建角色.它们工作得很好,但如果角色名称包含空格,我就有问题了.它将第二个单词计入第二个参数,使命令产生错误.

                  In my discord bot, I have 2 commands do give and create roles. They work perfectly fine, but if the role name includes a space, I have an issue. It counts the second word toward the second argument, making the command produce an error.

                  # Giverole
                  @client.command(name='giverole',
                                  aliases=['gr'],
                                  brief='Assgins role to a user',
                                  pass_ctx=True)
                  async def giverole(ctx, rname, *, member: discord.Member):
                      role = get(member.guild.roles, name=rname)
                      await member.add_roles(role)
                      await ctx.send(f'Role added to user {member.mention}')
                      print('Giverole command executed
                  - - -')
                  
                  # Createrole
                  
                  @client.command(name='createrole',
                                  brief='Creates a role',
                                  aliases=['cr','makerole'],
                                  pass_ctx=True)
                  async def createrole(ctx, rname: str, clr: discord.Colour):
                      if ctx.author.guild_permissions.manage_roles:
                          await ctx.guild.create_role(name=rname, colour=clr)
                          await ctx.send('Role created with name: ' + rname)
                          print('Createrole command executed
                  -  -  -')
                      else:
                          await ctx.send('You lack permission.')
                      print('Createrole command executed
                  -  -  -')
                  

                  理想情况下,我应该能够执行 k!giverole Bot Tester @user 之类的操作,但我得到了无效用户"错误.我有什么方法可以支持角色名称中的空格吗?提前致谢!

                  Ideally, I should be able to do something like k!giverole Bot Tester @user, but instead I get an "Invalid user" error. Is there any way for me to support spaces in the role name? Thanks in advance!

                  推荐答案

                  你有几个选择:

                  1. 使用角色转换器并要求提及角色:

                  1. Use a role converter and require the role to be mentioned:

                  async def giverole(ctx, role: discord.Role, member: discord.Member):
                  

                2. 要求角色用引号括起来:

                3. Require the role to be wrapped in quotes:

                  k!giverole "Bot Tester" @user
                  

                4. 切换两个参数的位置,以便转换后的用户排在第一位,并且可能有间隔的名称作为仅关键字参数出现.

                5. Switch the positions of the two arguments so that the converted user comes first, and the potentially spaced name comes as the keyword-only argument.

                  async def giverole(ctx, member: discord.Member, *, rname):
                  

                6. 我会推荐第一个选项,但您也可以尝试其他选项,看看您更喜欢哪个.

                  I would recommend the first option, but you may want to try the others as well to see which one you prefer.

                  这篇关于有没有办法在我的论点中包含空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:检查用户是否在 discord.py 中具有权限 下一篇:discord.py send_message 用法

                  相关文章

                  最新文章

                    <bdo id='FsdtQ'></bdo><ul id='FsdtQ'></ul>
                7. <small id='FsdtQ'></small><noframes id='FsdtQ'>

                8. <legend id='FsdtQ'><style id='FsdtQ'><dir id='FsdtQ'><q id='FsdtQ'></q></dir></style></legend>

                  <tfoot id='FsdtQ'></tfoot>

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