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

2024-05-08 05:03:51 发布

您现在位置:Python中文网/ 问答频道 /正文

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

@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!**")

0条回答
网友
1楼 · 发布于 2024-05-08 05:03:51

您的命令逻辑不正确:

  1. 它接受您在args中传递的内容(?verification test string(test, string)
  2. 检查从args生成的作者、频道和字符串是否等于您等待的消息
  3. 你不会把你收到的信息分配到任何地方

我建议采用以下方法之一:

  • 使用命令参数(?verification Role Name角色Role Name创建

    @bot.command()
    async def verification(ctx, *, rolename: str): 
    """Create verification role""" 
    # first kwarg is "consume-rest" argument for commands: https://discordpy.readthedocs.io/en/v1.3.4/ext/commands/commands.html#keyword-only-arguments
        await ctx.guild.create_role(name=rolename, hoist=True, reason="Verification Role Creation", colour=discord.Colour(0x979c9f))
        await ctx.send("**Type ?verify to gain Access to the Server!**")
    
  • 使用实际的消息响应(?verificationBot询问:What do you want to Name the Role?用户响应(示例中)Role Name角色Role Name创建`

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

相关问题 更多 >