Я пытаюсь использовать бота Discord, чтобы взаимодействовать с пользователем по сообщениям с помощью кнопок, но мне выдоют ошибку "This interac"

Вот код, с которым я тестирую:

import discord
from discord.ext import commands
import random
TOKEN = ''
intents = discord.Intents.all()
bot = commands.Bot(command_prefix="*", intents=intents)
 class MyView(discord.ui.View):
    def __init__(self):
        super().__init__(timeout=None)
@bot.event
 async def on_ready():   
       print(f"Connecté en tant que {bot.user} !")
@bot.command()
async def ghost(ctx):
    try:
        button1 = discord.ui.Button(style=discord.ButtonStyle.primary, label="карточка", custom_id="bouton1")
        button2 = discord.ui.Button(style=discord.ButtonStyle.success, label="характеристика", custom_id="bouton2")
        button3 = discord.ui.Button(style=discord.ButtonStyle.danger, label="призрак", custom_id="bouton3")
        button4 = discord.ui.Button(style=discord.ButtonStyle.danger, label="локация", custom_id="bouton4")      
        view = discord.ui.View()
        view.add_item(button1)
        view.add_item(button2)
        view.add_item(button3)
        view.add_item(button4)   
        await ctx.send("Да, начнеться веселье:)", view=view)
        def check(interaction):
            return interaction.user.id == ctx.author.id and interaction.message.id == ctx.message.id
        interaction = await bot.wait_for("button_click", check=check)

        interaction = await bot.wait_for("button_click")
        if interaction.component.custom_id == "bouton1":
            await interaction.respond(content="Bouton 1 cliqué !")
        elif interaction.component.custom_id == "bouton2":
            await interaction.respond(content="Bouton 2 cliqué !")
            random_number = random.randint(1, 100)  # Генерация случайного числа от 1 до 100
            await interaction.respond(content=f"Случайное число: {random_number}")
        elif interaction.component.custom_id == "bouton3":
            await interaction.respond(content="Bouton 3 cliqué !")
        elif interaction.component.custom_id == "bouton4":
            await interaction.respond(content="Bouton 4 cliqué !")    
    except Exception as e:
        print(f"Une erreur s'est produite : {e}")
pass
bot.run('')

Что-то не так с этим кодом? И если не сложно, то можно написать, как правильно писать рандом, не цифрами, а словами в строках. Заранее большое спасибо.


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