@holoi_name

Не происходит on_connect сообщения, что делать?

Не работает кнопка в сообщение, Ошибка взаимодействия.
6538ede0cbc28147088196.png

@commands.Cog.listener()
    async def on_connect(self):
        if self.persistents_views_added:
           retrun
           
        self.bot.add_view(ReportView(), message_id=1166681544774144011)


Весь код:
import disnake
from disnake.ext import commands


class ReportModal(disnake.ui.Modal):
    def __init__(self, arg):
        self.arg = arg 
        
        components = [
            disnake.ui.TextInput(label="Никнейм нарушителя (ID)", placeholder="Введите ник или айди нарушителя ", custom_id="name"),
            disnake.ui.TextInput(label="Нарешеное правила", placeholder="Введите ваш возраст", custom_id="rules"),
            disnake.ui.TextInput(
                label="Дополнительная информация. ",
                placeholder="Введите сюда ссылку на фрагмент видео или фото",
                custom_id="info",
                style=disnake.TextInputStyle.paragraph,
                min_length=10,
                max_length=500,
            ) 
        ]

        super().__init__(title='Жалоба', components=components, custom_id="recruitementModal")

    async def callback(self, interaction: disnake.ModalInteraction) -> None:
        name = interaction.text_values["name"]
        rules = interaction.text_values["rules"]
        info = interaction.text_values["info"]
        embed = disnake.Embed(color=0x2F3136, title="Жалоба отправлена!")
        embed.description = f"{interaction.author.mention}, Благодарим вас за вашу жалобу! " \
                            f"Администрация рассмотрит её в ближайшее время."
        embed.set_thumbnail(url=interaction.author.display_avatar.url)
        await interaction.response.send_message(embed=embed, ephemeral=True)
        channel = interaction.guild.get_channel(1166386987968761896)
        embed = disnake.Embed(
            title="Новая жалоба!",
            description=f"Пользователь пожаловавшийся: {interaction.author.mention} \n Нарушитель: {name}  \n Нарушеное правило: {rules} \n Дополнительная информация:** {info}"
        )
        view = ReportModerView()
        await channel.send('<@&1130452217804116080>', embed=embed, view=view)


class ReportView(disnake.ui.View):
    def init(self):
        super().init(timeout=None)

    @disnake.ui.button(label="Подать жалобу", style=disnake.ButtonStyle.gray, custom_id="button1")
    async def button1(self, button: disnake.ui.Button, interaction: disnake.Interaction):
        await interaction.response.send_modal(ReportModal(""))
        await interaction.response.defer()

class ReportModerView(disnake.ui.View):
    def init(self):
        super().init(timeout=None)

    @disnake.ui.button(label="Принять", style=disnake.ButtonStyle.green, custom_id="button2")
    async def button2(self, button: disnake.ui.Button, interaction: disnake.Interaction):
        user = disnake.utils.get(interaction.guild.members, mention=f"{interaction.author.mention}")
        if interaction.response.is_done():
            return

        user = disnake.utils.get(interaction.guild.members, mention=f"{interaction.author.mention}")
        await user.send('Ваша жалоба принята!')
        deny = disnake.Embed(
            title = 'Жалоба принята!',
            description = f'Пользователь пожаловавшийся: {interaction.author.mention}'
        )
        await interaction.response.edit_message(embed=deny)

    @disnake.ui.button(label="Отказать", style=disnake.ButtonStyle.red, custom_id="button3")
    async def button3(self, button: disnake.ui.Button, interaction: disnake.Interaction):
        if interaction.response.is_done():
            return

        user = disnake.utils.get(interaction.guild.members, mention=f"{interaction.author.mention}")
        await user.send('Ваша жалоба отклонена!')
        deny = disnake.Embed(
            title = 'Жалоба откланена!',
            description = f'Пользователь пожаловавшийся: {interaction.author.mention}'
        )
        await interaction.response.edit_message(embed=deny)

class Report(commands.Cog):
    def init(self, bot):
        self.bot = bot
        self.persistents_views_added = False

    @commands.command()
    async def report(self, ctx):
        view = ReportView()
        embed = disnake.Embed(
            title="Жалоба!",
            description="Если вы увидели, что кто-то нарушил правила вы можете сообщить это администрации."
        )
        embed.set_image(url='https://media.discordapp.net/attachments/925437425705177198/925722006769516544/d86vc6l-aae1960e-52c0-42b4-a56a-db7e0871b391.gif?ex=65423fcd&is=652fcacd&hm=5ae82d3fbf04e2300daaeebb58c6859f97c408c2b8e02a40b05a20f2a0abc20d&=')

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

    @commands.Cog.listener()
    async def on_connect(self):
        if self.persistents_views_added:
           retrun
           
        self.bot.add_view(ReportView(), message_id=1166681544774144011)


def setup(bot):
    bot.add_cog(Report(bot))
  • Вопрос задан
  • 48 просмотров
Пригласить эксперта
Ответы на вопрос 1
Vindicar
@Vindicar
RTFM!
async def on_connect(self):
        if self.persistents_views_added:
           retrun


retrun? Может, всё-таки return?
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы