Здравствуйте я пишу бота на python для дискорд который будет использоваться для получения роли на любом сервере но при вводе команды бота для выдачи в консоли бота выскакивает ошибка :
Ignoring exception in command protect:
Traceback (most recent call last):
File "C:\Users\Kirill-pc\AppData\Local\Programs\Python\Python37\lib\site-packa
ges\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "C:\Users\Kirill-pc\Desktop\admin\bot.py", line 23, in protect
await author.add_roles(role)
File "C:\Users\Kirill-pc\AppData\Local\Programs\Python\Python37\lib\site-packa
ges\discord\member.py", line 777, 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\Kirill-pc\AppData\Local\Programs\Python\Python37\lib\site-packa
ges\discord\ext\commands\bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\Kirill-pc\AppData\Local\Programs\Python\Python37\lib\site-packa
ges\discord\ext\commands\core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\Kirill-pc\AppData\Local\Programs\Python\Python37\lib\site-packa
ges\discord\ext\commands\core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: Att
ributeError: 'NoneType' object has no attribute 'id'
вот код бота:
import discord
from discord.ext import commands
TOKEN = "OTUwMjIxNTUyMDkwMjM0OTAw.YiVwyA.TGXuUXTYpH80ujpqqLa0B9UI4Gk"
bot = commands.Bot(command_prefix=('ab.'))
bot.remove_command( 'help' )
@bot.event
async def on_ready():
print("Я запущен!")
@bot.command()
async def pro(ctx):
await ctx.send('Недостаточно прав')
@bot.command()
async def protect(ctx):
author = ctx.message.author
guild = bot.get_guild(805137789661872129)
role = guild.get_role(940997266100064316)
await author.add_roles(role)
bot.run(TOKEN)