[Python] events Pin and Unpin discord.py

Discussão em 'Python' iniciado por Stack, Março 9, 2025.

  1. Stack

    Stack Membro Participativo

    i have one problem with events on_message_pin and on_message_unpin, both events should be invoked when message is pinned or unpinned, but in my scritp this in no working. I have every intenses i need, and i have good permisions for bot in discord developer portal and role on discord server. Im trying to do a logging system which is sending a message on special logs channel, and everything i want is working and just not this these two events, can somoeone tell me what im a doing wrong? I have version of pip 2.4.0, and python version 3.11. I dont have problem with webhook_url.

    @bot.event
    async def on_message_pin(message):
    """Logowanie przypinania wiadomości."""
    print(f"Przypinanie wiadomości: {message.id} w kanale {message.channel.id}")
    if message.pinned: # Sprawdzamy, czy wiadomość jest przypięta
    webhook_url = get_webhook_url(message.guild.id)
    if webhook_url:
    print(f"Wysyłanie logu do webhooka: {webhook_url}")
    embed = discord.Embed(title=" Przypięto wiadomość", color=discord.Color.green())
    embed.add_field(name="Kto przypiął:", value=message.author.mention, inline=False)
    embed.add_field(name="Kanał:", value=f"{message.channel.mention}", inline=False)
    embed.add_field(name="Link do wiadomości:", value=f"[Kliknij tutaj](https://discord.com/channels/{message.guild.id}/{message.channel.id}/{message.id})", inline=False)

    async with aiohttp.ClientSession() as session:
    webhook = Webhook.from_url(webhook_url, session=session)
    await webhook.send(embed=embed)
    print("Log wiadomości przypiętej został wysłany.")


    @bot.event
    async def on_message_unpin(message):
    Logowanie odpinania wiadomości.
    print(f"Odpinanie wiadomości: {message.id} w kanale {message.channel.id}")
    if not message.pinned:
    webhook_url = get_webhook_url(message.guild.id)
    if webhook_url:
    print(f"Wysyłanie logu do webhooka: {webhook_url}")
    embed = discord.Embed(title=" Odpinanie wiadomości", color=discord.Color.red())
    embed.add_field(name="Kto odpiął:", value=message.author.mention, inline=False)
    embed.add_field(name="Kanał:", value=f"{message.channel.mention}", inline=False)
    embed.add_field(name="Link do wiadomości:", value=f"[Kliknij tutaj](https://discord.com/channels/{message.guild.id}/{message.channel.id}/{message.id})", inline=False)

    async with aiohttp.ClientSession() as session:
    webhook = Webhook.from_url(webhook_url, session=session)
    await webhook.send(embed=embed)
    print("Log wiadomości odpiętej został wysłany.")

    Continue reading...

Compartilhe esta Página