Не работает выдача ролей в discord.py
Я хочу, чтобы бот выдавал роль, id которой получит из БД. Но у меня не работает.
Вот ошибка:
Ignoring exception in command test:
Traceback (most recent call last):
File "/home/runner/manul/venv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "main.py", line 86, in test
await ctx.author.add_roles(role)
File "/home/runner/manul/venv/lib/python3.8/site-packages/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 "/home/runner/manul/venv/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "/home/runner/manul/venv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "/home/runner/manul/venv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'id'
Код команды: https://pastebin.com/zvmp1RXS
Ответы (1 шт):
Автор решения: RAINGM
→ Ссылка
@bot.command()
async def test(ctx):
cursor.execute(f"SELECT verify_role FROM role WHERE id = {ctx.author.guild.id}")
verify_role = cursor.fetchone()
if verify_role != None:
role = discord.utils.get(ctx.guild.roles, id=verify_role[0])
await ctx.author.add_roles(role)
await ctx.message.add_reaction('✅')