Is there a way to include spaces in my argument?

后端 未结 1 1863
谎友^
谎友^ 2020-12-22 04:27

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 to

相关标签:
1条回答
  • 2020-12-22 05:13

    You have a few options:

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

      async def giverole(ctx, role: discord.Role, member: discord.Member):
      
    2. Require the role to be wrapped in quotes:

      k!giverole "Bot Tester" @user
      
    3. 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):
      

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

    0 讨论(0)
提交回复
热议问题