Webhooks

WebhookType

class acord.WebhookType(value)[source]

An enumeration.

Webhook

class acord.Webhook(*, conn: Any = None, id: acord.models.Snowflake, type: acord.webhooks.types.WebhookType, guild_id: acord.models.Snowflake = None, channel_id: acord.models.Snowflake = None, user: acord.models.user.User = None, name: str = None, avatar: pydantic.networks.AnyHttpUrl = None, token: str = None, application_id: acord.models.Snowflake = None, url: str = None)[source]

Representation of a discord webhook

This class can simply be used for sending simple messages, and editing and deleting them. Only IF you stick to the default session.

If you pass your client through the args, or overwrite Webhook.conn with Client.http. Your able to properly interact with the generated message object.

Note

When dealing with interactions, it is recommended to use the webhook class, instead of Interaction

async delete(*, reason: Optional[str] = None, with_token: bool = True, auth: Optional[str] = None) None[source]

This function is a coroutine.

Deletes webhook

Parameters
  • reason (str) – reason for deleting webhook

  • with_token (bool) – Whether to delete with token or not, defaults to True

  • auth (str) – If not with_token, auth is your BOT TOKEN, which will be used to make request

async delete_message(message_id: acord.models.Snowflake, *, thread_id: Optional[acord.models.Snowflake] = None, reason: Optional[str] = None, use_application_id: bool = False) None[source]

This function is a coroutine.

Deletes a message sent by webhook

Parameters
  • message_id (Snowflake) – ID of message to delete

  • thread_id (Snowflake) – ID of thread message was sent in

  • reason (str) – Reason for deleting message

  • use_application_id (bool) – Whether to use application ID instead of webhook ID

async edit(*, reason: Optional[str] = None, with_token: bool = True, auth: Optional[str] = None, **kwds) acord.webhooks.webhook.Webhook[source]

This function is a coroutine.

Edits webhook.

Parameters
  • name (str) – New name of webhook, still cannot be called clyde

  • avatar (File) – New avatar for webhook

  • channel_id (Snowflake) – New channel to move webhook to

  • reason (str) – reason for editing webhook

  • with_token (bool) – Whether to modify with token or not, defaults to True

  • auth (str) – If not with_token, auth is your BOT TOKEN, which will be used to make request

async edit_message(message_id: acord.models.Snowflake, *, thread_id: Optional[acord.models.Snowflake] = None, use_application_id: bool = False, **kwds) acord.models.message.WebhookMessage[source]

This function is a coroutine.

Edits a previously sent message from this webhook

Note

This function accepts all parameters from Message.edit, as a well a few extras which are documented below.

Parameters
  • message_id (Snowflake) – ID of message to edit

  • thread_id (Snowflake) – ID of thread message was sent in

  • use_application_id (bool) – Whether to use the application ID instead of the Webhook ID

async execute(*, wait: bool = False, thread_id: Optional[acord.models.Snowflake] = None, **kwds) Optional[acord.models.message.WebhookMessage][source]

This function is a coroutine.

Executes a webhook.

Note

This function accepts all parameters from TextChannel.send, as a well a few extras which are documented below.

Parameters
  • wait (bool) – Whether to wait for message created to be returned

  • thread_id (Snowflake) – ID of the thread to send message in

  • username (str) – Username to override default username

  • avatar_url (str) – URL of avatar to override default avatar

async fetch_message(message_id: acord.models.Snowflake, *, thread_id: Optional[acord.models.Snowflake] = None, use_application_id: bool = False) acord.models.message.WebhookMessage[source]

This function is a coroutine.

Fetches a message sent by the webhook

Parameters
  • message_id (Snowflake) – ID of message to fetch

  • thread_id (Snowflake) – ID of thread message is in

  • use_application_id (bool) – Whether to use the application id instead of the webhook id when fetching message

async respond_to_autocomplete(choices: List[acord.ext.application_commands.option.AutoCompleteChoice]) None[source]

This function is a coroutine.

Responds to an interaction with a list of choices

Parameters

choices (List[AutoCompleteChoice]) – List of choices to return the user, can be a list of dicts with the mapping name: value

async respond_with_message(**kwds) None[source]

This function is a coroutine.

Responds to an interaction using a regular message

Danger

This method should only be if Webhook.type is 3. As it will fail for any other type of webhook.

Note

All parameters from TextChannel.send() are valid, additional parameters documented below

Parameters
  • flags (IMessageFlags) – Flags for message

  • ack (bool) – Whether to ack the response, giving the client 15 mins to edit to this response.

async respond_with_modal(modal: acord.bases.components.Modal) None[source]

This function is a coroutine.

Responds to an interaction using a modal.

Parameters

modal (Modal) – Modal to respond with

async send_followup_message(**kwds) None[source]

This function is a coroutine.

Sends a followup message to an interaction

Note

All parameters from TextChannel.send() are valid, any additional parameters documented below

Parameters

flags (IMessageFlags) – Flags for message

application_id: Optional[acord.models.Snowflake]

the bot/OAuth2 application that created this webhook

avatar: Optional[pydantic.networks.AnyHttpUrl]

the default user avatar hash of the webhook

channel_id: Optional[acord.models.Snowflake]

the channel id this webhook is for, if any

guild_id: Optional[acord.models.Snowflake]

the guild id this webhook is for, if any

id: acord.models.Snowflake

the id of the webhook

name: str

the default name of the webhook

token: Optional[str]

the secure token of the webhook (returned for Incoming Webhooks)

type: acord.webhooks.types.WebhookType

the type of the webhook

url: Optional[str]

the url used for executing the webhook

user: Optional[acord.models.user.User]

the user this webhook was created by (not returned when getting a webhook with its token)

WebhookConnection

Methods
class acord.webhooks.connection.WebhookConnection(*, loop: asyncio.events.AbstractEventLoop = <_UnixSelectorEventLoop running=False closed=False debug=False>, session: typing.Optional[aiohttp.client.ClientSession] = None, client: typing.Optional[typing.Any] = None, **kwds)[source]

Base webhook connection, wraps the session to be compatible with other ACord objects.

Parameters
  • loop (asyncio.AbstractEventLoop) – Loop to create connection off of

  • session (ClientSession) – A pre-existing session to use

  • client (Client) –

    Client to attach webhook to.

    Danger

    If this param is provided, :param:`WebhookConnection.session` is ignored.

    We will instead use the session generated by the client

  • **kwds

    Additional kwargs to pass through session, if it has not been provided.

    Note

    You may not provide the loop param through kwds, use :param:`WebhookConnection.loop`.

async request(route: acord.core.abc.Route, **kwds) aiohttp.client_reqrep.ClientResponse[source]