Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/342.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我如何使它读取用户所说的内容并使用它来创建角色?不和谐_Python_Discord_Discord.py - Fatal编程技术网

Python 我如何使它读取用户所说的内容并使用它来创建角色?不和谐

Python 我如何使它读取用户所说的内容并使用它来创建角色?不和谐,python,discord,discord.py,Python,Discord,Discord.py,好的,我想这样做,它会问你想给它命名什么角色,然后你输入它,它会说键入“?验证以获得对服务器的访问权限!”我目前得到了这个,但它不起作用:/需要帮助吗 @bot.command() async def verification(ctx, *args): guild = ctx.guild msg = ' '.join(args) def check(message): return message.author == ctx.author and message.channe

好的,我想这样做,它会问你想给它命名什么角色,然后你输入它,它会说键入“?验证以获得对服务器的访问权限!”我目前得到了这个,但它不起作用:/需要帮助吗

@bot.command()
async def verification(ctx, *args):
  guild = ctx.guild
  msg = ' '.join(args)
  def check(message):
    return message.author == ctx.author and message.channel == ctx.channel and message.content.lower() == msg
  await ctx.send("What do you want to Name the Role?")
  await bot.wait_for('message', check=check, timeout=60)
  await guild.create_role(name=msg, hoist=True, reason="Verification Role Creation", colour=discord.Colour(0x979c9f))
  await ctx.send("**Type ?verify to gain Access to the Server!**")

您的命令逻辑不正确:

  • 它接受您在args中传递的内容(
    ?验证测试字符串
    (测试,字符串)
  • 检查从args生成的作者、频道和字符串是否等于您等待的消息
  • 你不会把你收到的信息分配到任何地方
  • 我建议采用以下方法之一:

    • 使用命令参数(
      ?验证角色名称
      → 角色
      角色名称
      已创建)

      @bot.command()
      异步def验证(ctx,*,角色名称:str):
      “”“创建验证角色”“”
      #第一个kwarg是命令的“使用rest”参数:https://discordpy.readthedocs.io/en/v1.3.4/ext/commands/commands.html#keyword-只有论点
      等待ctx.guild.create_角色(name=rolename,chift=True,reason=“验证角色创建”,color=discord.color(0x979c9f))
      等待ctx.send(“**类型?验证以获得对服务器的访问权!**”)
      
    • 使用实际消息响应(
      ?验证
      → Bot询问:
      您想给角色命名什么?
      →使用(示例中)
      角色名称的用户响应→角色
      角色名称
      已创建`

      @bot.command()
      异步def验证(ctx):
      “”“创建验证角色”“”
      def检查(消息):
      返回message.author==ctx.author和message.channel==ctx.channel
      等待ctx.send(“您想给角色命名什么?”)
      rolename=wait bot.wait_for('message',check=check,timeout=60)
      等待公会。创建_角色(name=rolename,hugh=True,reason=“验证角色创建”,color=discord.color(0x979c9f))
      等待ctx.send(“**类型?验证以获得对服务器的访问权!**”)