Бот выдаёт ошибку "Ошибка взаимодействия" в discord.py

Решил попробовать сделать рабочие кнопки в PM бота, который будет менять цвет выбраной кнпоки на зелёный, а остольных на красный, но выдаёт ошибку взаимодействия. Помогите пожалуйста

import discord
from discord.ext import commands

intents = discord.Intents.default()
intents.message_content = True
bot = commands.Bot(command_prefix='$', intents=intents)


@bot.event
async def on_ready():
    print(f"Bot {bot.user}, ready!")


@bot.event
async def on_reaction_add(reaction, user):
    custom_emoji = discord.PartialEmoji(name=':toppng:', id=1109072104160231495)
    if reaction.emoji == custom_emoji:
        user_id = user.id
        user_obj = await bot.fetch_user(user_id)

        embed = discord.Embed(title="Button Demo")
        embed.description = "Click on a button to get the desired text."

        button1 = discord.ui.Button(style=discord.ButtonStyle.primary, label="Button 1", custom_id="button1")
        button2 = discord.ui.Button(style=discord.ButtonStyle.primary, label="Button 2", custom_id="button2")
        button3 = discord.ui.Button(style=discord.ButtonStyle.primary, label="Button 3", custom_id="button3")
        button4 = discord.ui.Button(style=discord.ButtonStyle.primary, label="Button 4", custom_id="button4")

        view = discord.ui.View()
        view.add_item(button1)
        view.add_item(button2)
        view.add_item(button3)
        view.add_item(button4)

        message = await user_obj.send(embed=embed, view=view)
        view.message = message

@bot.event
async def on_button_click(interaction):
    selected_button = interaction.component

    # Handle button clicks and send the desired text
    if selected_button.custom_id == "button1":
        await interaction.user.send("You clicked Button 1")
    elif selected_button.custom_id == "button2":
        await interaction.user.send("You clicked Button 2")
    elif selected_button.custom_id == "button3":
        await interaction.user.send("You clicked Button 3")
    elif selected_button.custom_id == "button4":
        await interaction.user.send("You clicked Button 4")

    selected_button.style = discord.ButtonStyle.success
    for button in interaction.message.components[0].components:
        if button != selected_button:
            button.style = discord.ButtonStyle.danger

    await interaction.message.edit(components=[interaction.message.components[0]])

    await interaction.response.defer()


@bot.event
async def on_component(interaction):
    if isinstance(interaction, discord.Interaction):
        await bot.process_commands(interaction)

Ответы (0 шт):