Как мне сделать так, чтобы он читал то, что говорит пользователь, и использовал это для создания роли? discord.py - PullRequest
0 голосов
/ 13 июля 2020

Хорошо, поэтому я хочу сделать так, чтобы он спрашивал вас, какую роль вы хотите назвать, затем вы вводите это, и он говорит: Введите "? Подтвердите, чтобы получить доступ к серверу!" Я получил это, но не работает: / нужна помощь

@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 Ответ

1 голос
/ 13 июля 2020

Логи вашей команды c неверен:

  1. Требуется то, что вы передаете в args (?verification test string(test, string))
  2. Проверяет автора, канал и Строка , построенная из аргументов, равна сообщению, которое вы ждете .
  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!**")
    
  • Использовать фактический ответ на сообщение (?verificationБот спрашивает: 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!**")
    
...