Команда в боте Discord о добавлении роли не работает - PullRequest
0 голосов
/ 08 мая 2020

Итак, я хотел добавить команду в моем боте Discord, где вы можете добавлять роли участникам. Это ошибка.

@bot.command()
@commands.has_permissions(administrator=True)
async def approve(ctx, arg1, member: discord.Member = None):
    if not arg1:
        await ctx.send("Please specify the role")
    if not member:
        await ctx.send("Please specify a member")
    await ctx.channel.purge(limit=1)
    user = ctx.message.author
    role = discord.utils.get(ctx.guild.roles, name=arg1)
    await member.add_roles(role)
    await ctx.send(f"Congratulations {member.mention} :tada:"
                   f"You successfully passed the test for {arg1} :hugging: \n"
                   f"Tested by {user.name}.")

Но я продолжаю получать эту ошибку:

Ignoring exception in command approve:
Traceback (most recent call last):
  File "C:\Users\gg\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 83, in wrapped
    ret = await coro(*args, **kwargs)
  File "C:/Users/gg/Desktop/Στέλιος/phoenix/phoenix-bot.py", line 29, in approve
    await member.add_roles(role)
  File "C:\Users\gg\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\member.py", line 641, in add_roles
    await req(guild_id, user_id, role.id, reason=reason)
AttributeError: 'NoneType' object has no attribute 'id'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\gg\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\bot.py", line 892, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\gg\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 797, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\Users\gg\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 92, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'id'

Что я могу сделать, чтобы он работал

...