Если задать несколько задач через команду !задача дата текст_задачи то появятся в нужном канале все задачи. Но если у любой из них нажать на кнопку взаимодействия, то у других задач кнопки уже работать не будут. Прошу подсказать как это исправить. Нужно, чтобы при нажатии на кнопку удалялась конкретная задача, на которой нажали кнопку и чтобы кнопки у других задач работали. Не могу понять как это сделать.
@bot.command(name="задание", aliases=['задача'])
async def task_day(ctx: commands.Context, date: str = None, *task: str) -> None:
await ctx.message.delete() # удаляем сообщение автора задачи
if date is None:
await ctx.send(embed=discord.Embed(
description='**:grey_exclamation: Обязательно укажи дату! Пример команды: \n!задача 01.01.2000 твое задание**'))
return
elif not task:
await ctx.send(embed=discord.Embed(
description='**:grey_exclamation: Обязательно укажи задание! Пример команды: \n!задача 01.01.2000 твое задание**'))
return
category = discord.utils.get(ctx.guild.categories, name="Задачи") # пытаемся получить категорию с именем Задачи
if not category: # если такой нет, то
category = await ctx.guild.create_category(name="Задачи") # создаем категорию
task = " ".join(task)
date = date.replace(".", "-") # заменяем в дате все точки знаками тире
channel = discord.utils.get(category.channels, name=date) # работаем с категорией
if not channel: # если нет канала с именем аргумента data
channel = await ctx.guild.create_text_channel(date, category=category) # создаем такой канал
await channel.send( # шлем туда сообщение
embed=discord.Embed(title="Новая задача!", description=task, colour=0x4169E1),
components=[[
Button(style=ButtonStyle.green, label='Готово'),
Button(style=ButtonStyle.red, label='Отказываюсь')
]]
)
response = await bot.wait_for("button_click")
if response.channel == channel:
if response.component.label == 'Готово':
await response.respond(content='Отлично!')
await ctx.message.delete()
channel = bot.get_channel(951917790518988830) # куда шлем отчеты о выполнении задач
await channel.send(
embed=discord.Embed(title='Задача выполнена!', description=(f'**{response.user.display_name}** подтвердил выполнение задачи **"{task}"**. Задача закрыта.' ), colour=0x4169E1)
)
elif response.component.label == 'Отказываюсь':
await response.respond(content='Принято!')
await ctx.message.delete()
channel = bot.get_channel(951917790518988830) # куда шлем отчеты о выполнении задач
await channel.send(
embed=discord.Embed(title='Задача НЕ выполнена!', description=(f'**{response.user.display_name}** отказался от выполнения задачи **"{task}"**. Задача закрыта.' ), colour=0x4169E1)
)
await channel.send( # шлем туда сообщение
embed=discord.Embed(title="Новая задача!", description=task, colour=0x4169E1),
components=[[
Button(style=ButtonStyle.green, label='Готово', custom_id=f"{ctx.id}:ready"),
Button(style=ButtonStyle.red, label='Отказываюсь', custom_id=f"{ctx.id}:close")
]]
)
Получаю ошибку
Ignoring exception in command задание:
Traceback (most recent call last):
File "/home/runner/DiscordGarwinVRN/venv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "main.py", line 103, in task_day
Button(style=ButtonStyle.green, label='Готово', custom_id=f"{ctx.id}:ready"),
AttributeError: 'Context' object has no attribute 'id'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/runner/DiscordGarwinVRN/venv/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "/home/runner/DiscordGarwinVRN/venv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "/home/runner/DiscordGarwinVRN/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: 'Context' object has no attribute 'id'