繁体   English   中英

我如何制作它以读取用户所说的内容并使用它来扮演角色? discord.py

[英]How do i make it so it reads what the user says and uses it to make a role? 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.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!**")

您的命令逻辑不正确:

  1. 它需要您传入 args 的内容( ?verification test string(test, string)
  2. 检查从 args 构建的作者、频道和字符串是否等于您等待的消息
  3. 你不会分配你在任何地方得到的消息。

我建议通过以下方式之一执行此操作:

  • 使用命令 args ( ?verification Role Namerole Role Name created )

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM