<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. 有没有办法在我的论点中包含空格?

        Is there a way to include spaces in my argument?(有没有办法在我的论点中包含空格?)
          • <bdo id='6tVax'></bdo><ul id='6tVax'></ul>
          • <small id='6tVax'></small><noframes id='6tVax'>

                    <tbody id='6tVax'></tbody>
                  <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>
                  本文介绍了有没有办法在我的论点中包含空格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  在我的 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):
                  

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

                2. Require the role to be wrapped in quotes:

                  k!giverole "Bot Tester" @user
                  

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

                4. 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):
                  

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

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

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

                  【网站声明】本站部分内容来源于互联网,旨在帮助大家更快的解决问题,如果有图片或者内容侵犯了您的权益,请联系我们删除处理,感谢您的支持!

                  相关文档推荐

                  How to make a discord bot that gives roles in Python?(如何制作一个在 Python 中提供角色的不和谐机器人?)
                  Discord bot isn#39;t responding to commands(Discord 机器人没有响应命令)
                  Can you Get the quot;About mequot; feature on Discord bot#39;s? (Discord.py)(你能得到“关于我吗?Discord 机器人的功能?(不和谐.py))
                  message.channel.id Discord PY(message.channel.id Discord PY)
                  How do I host my discord.py bot on heroku?(如何在 heroku 上托管我的 discord.py 机器人?)
                  discord.py - Automaticaly Change an Role Color(discord.py - 自动更改角色颜色)
                      <bdo id='FsdtQ'></bdo><ul id='FsdtQ'></ul>
                    • <small id='FsdtQ'></small><noframes id='FsdtQ'>

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

                        <tbody id='FsdtQ'></tbody>

                        <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>