Этот вопрос закрыт для ответов, так как повторяет вопрос Как скрыть сообщение «ошибка взаимодействия» в боте?
@Vasiliy009

Не работает кнопка, ошибка «Ошибка взаимодействия» в discord py, из за чего?

Хотел сделать команду жалобу /report
Что то идет не так, проверил код, вроде бы все хорошо, но после нажатия на кнопку, выводила ошибка "Ошибка взаимодействия"
Перепроверил, вроде нету никакой ошибки
Ее суть, при команде /report создается embed с кнопкой, с которой должен взаимодействовать администратор, после нажатия на кнопки, участник который написал жалобу в /report должен получить в личные сообщение, о том что ему было отказано, или же одобрено
Код
import asyncio
import discord 
from discord.ui import Button, View
from discord.ext import commands
import re

class ReportView(View):
    def __init__(self, ctx):
        super().__init__()
        self.ctx = ctx

    async def interaction_check(self, interaction: discord.Interaction) -> bool:
        # Check if the interaction is from the user who initiated the report
        if interaction.user.id != self.ctx.author.id:
            await interaction.response.send_message("Это не ваша команда!", ephemeral=True)
            return False
        return True

    async def on_button_click(self, button: discord.ui.Button, interaction: discord.Interaction):
        # Send a message to the mentioned user when a button is clicked
        user_mention = self.ctx.options.get("участник")
        user_name = interaction.user.name
        user_id = interaction.user.id
        if button.label == "Гуд":
            p_emb = discord.Embed(title='Репорт',
                                  description=f"Пользователь `{user_mention.mention}` получил одобрение по вашей жалобе!",
                                  colour=discord.Color.green())
            p_emb.set_author(name=user_mention.name, icon_url=user_mention.avatar.url if user_mention.avatar else None)
            p_emb.set_footer(text=f"Действие выполнено пользователем - {user_name}",
                             icon_url=interaction.user.avatar.url if interaction.user.avatar else None)
            try:
                await user_mention.send(embed=p_emb)
            except discord.Forbidden:
                pass
        elif button.label == "Ногуд":
            p1_emb = discord.Embed(title='Репорт',
                                   description=f"Пользователь `{user_mention.mention}` получил отказ по вашей жалобе!\nПодробности вы можете узнать у `<@{user_id}>`",
                                   colour=discord.Color.red())
            p1_emb.set_author(name=user_mention.name, icon_url=user_mention.avatar.url if user_mention.avatar else None)
            p1_emb.set_footer(text=f"Действие выполнено пользователем - {user_name}",
                              icon_url=interaction.user.avatar.url if interaction.user.avatar else None)
            try:
                await user_mention.send(embed=p1_emb)
            except discord.Forbidden:
                pass
        button.disabled = True
        await interaction.response.edit_message(view=self)

class member(commands.Cog):
    def __init__(self, client):
        self.client: commands.client = client

    @commands.slash_command(name="report", description="Пожаловаться")
    async def report(self, ctx, участник = discord.Option(discord.User, description="Участник на которого вы хотите написать жалобу"), подробности = discord.Option(str, description="Опишите подробности на жалобу участника"), ссылка = discord.Option(str, description="Ссылку на оправдание данной жалобы")):
        if подробности == None:
            подробности = "Не указана"
        if "https" not in ссылка or "imgur" not in ссылка:
            emb = discord.Embed(title='Репорт', description="В поле 'ссылка' должны содержать ссылку или ключевое слово 'imgur'.", colour=discord.Color.red())
            await ctx.respond(embed=emb)
            await ctx.delete(delay=10)
            return

        if участник.id == ctx.author.id:
            emb = discord.Embed(title='Репорт', description=f"Вы не можете написать жалобу самому себе", colour=discord.Color.red())
            await ctx.respond(embed=emb)
            await ctx.delete(delay=10)
            return

        channel = self.client.get_channel(655646843291828249)

        if channel:
            correct_button = Button(label="Гуд", style=discord.ButtonStyle.success)
            incorrect_button = Button(label="Ногуд", style=discord.ButtonStyle.danger)

            view = ReportView(ctx)
            view.ctx = ctx
            view.add_item(correct_button)
            view.add_item(incorrect_button)

            embed = discord.Embed(title="Новый репорт", color=0x00ff00)
            embed.add_field(name="Отправитель", value=ctx.author.mention, inline=False)
            embed.add_field(name="Цель", value=участник.mention, inline=False)
            embed.add_field(name="Причина", value=подробности, inline=False)
            embed.add_field(name="Оправдание", value=ссылка, inline=False)

            await channel.send(embed=embed, view=view)

            emb = discord.Embed(title='Репорт', description="Отчет успешно отправлен, ожидайте рассмотра вашей жалобы!", colour=discord.Color.green())
            await ctx.respond(embed=emb)
            await ctx.delete(delay=10)
        
def setup(client):
    client.add_cog(member(client))
  • Вопрос задан
  • 64 просмотра
Ваш ответ на вопрос

Вопрос закрыт для ответов и комментариев

Потому что уже есть похожий вопрос.
Похожие вопросы