#Can't figure out this webhook thing. SOS

1 messages · Page 1 of 1 (latest)

woeful marsh
#
    @listen(MessageCreate)
    async def on_message_create(self, event: MessageCreate):
        message = event.message
        if message.webhook_id:
            webhook = await self.bot.http.get_webhook(
                webhook_id=message.webhook_id
            )

This results in

GET::https://discord.com/api/v10: 403
Ignoring exception in MessageCreate(): HTTPException: 403|Forbidden || internal network error

I've been trying to figure out how to get a webhook object for like 2 days now and need help keepincool

crimson voidBOT
#

Hey! Once your issue is solved, press the button below to close this thread!

woeful marsh
#

@paper abyss did you miss something?

#

the reason is because i need to listen for webhook messages to relay PluralKit proxy messages, and i came to this decision because skipping message.author.bot messages also skips webhooks. so i need to filter by getting the webhook name and checking if it begins with "PluralKit" or something

woeful marsh
#

bump

flint maple
#

@woeful marsh Two questions:

  1. Does your bot have access to the server the webhook is in?
  2. Can your bot see the channel that the webhook is in?
flint maple
#

Does your bot have permision to manage webhooks?

woeful marsh
flint maple
#

Pro-tip: 403's from the API only return if the application doesn't have access to it in some way. Unless you were trying to mess with beta features, (which then it's obvious you can't access it) you should check application permissions and the applied scopes it has

flint maple
woeful marsh
#

im tired

#

spent the whole day away from a computer servicing a vacuum and fixing a car lol

#

tomorrow maybe ill try

flint maple
#

I'm inclined to close this because I cannot replicate the issue you're having

#

With the correct permissions, this method works properly

woeful marsh
#

managed to get it working with this

async def get_webhook(self, webhook_id: Snowflake_Type) -> WebhookData:
    return cast(
        WebhookData,
        await self.bot.http.request(
            Route("GET", f"/webhooks/{webhook_id}", webhook_id=webhook_id)
        ),
    )
woeful marsh
#

full working example:

from interactions import (
    Extension,
    Message,
    message_context_menu,
    ContextMenuContext,
    Permissions,
    Snowflake_Type,
)
from interactions.api.http.route import Route

from typing import cast
from discord_typings import WebhookData

from config.config import SERVER_ID
from pasta import Client


class Debugging(Extension):
    def __init__(self, bot: Client):
        self.bot: Client = bot

    async def get_webhook(self, webhook_id: Snowflake_Type) -> WebhookData:
        return cast(
            WebhookData,
            await self.bot.http.request(
                Route("GET", f"/webhooks/{webhook_id}", webhook_id=webhook_id)
            ),
        )

    @message_context_menu(
        name="Get Message Info",
        scopes=[SERVER_ID],
        dm_permission=False,
        default_member_permissions=Permissions.ADMINISTRATOR,
    )
    async def get_message_info(self, ctx: ContextMenuContext):
        message = ctx.target
        if not isinstance(message, Message):
            return

        info = (
            f"**Message Info**\n"
            f"**Author:** {message.author}\n"
            f"**Content:** {message.content}\n"
            f"**Timestamp:** {message.timestamp}\n"
        )

        if webhook_id := message.webhook_id:
            webhook = await self.get_webhook(webhook_id)
            info += (
                f"**Webhook ID:** {webhook['id']}\n"
                f"**Webhook App ID:** {webhook['application_id']}\n"
                f"**Webhook Name:** {webhook['name']}\n"
            )

        await ctx.send(info, ephemeral=True)