Download the PHP package internet/intercord without Composer
On this page you can find all versions of the php package internet/intercord. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download internet/intercord
More information about internet/intercord
Files in internet/intercord
Package intercord
Short Description A library for sending payloads to discord via webhooks.
License MIT
Homepage https://doctor-internet.dev
Informations about the package intercord
InterCord
Discord webhooks for PHP: messages, rich embeds, files, components, threads and forum posts, with rate limits handled for you.
Upgrading from 2.x? See UPGRADE-3.0.md.
Installation
Requires PHP 8.3 or later. Guzzle is the default HTTP client; any PSR-18 client can be used instead.
Quick start
$url is the webhook URL from the channel's Integrations → Webhooks settings. Treat it as a password: anyone holding it can post, edit and delete as that webhook. Keep it in an environment variable or secret store, not in source control.
Webhook::fromCredentials($id, $token) builds the same thing from the two halves of the URL.
Messages
execute() sends and returns nothing. executeAndWait() waits for Discord to confirm, and returns the Message it created:
The same is available by ID, for messages you only stored the ID of:
Edits change only what you set. To remove something, clear it:
PayloadField covers Content, Embeds, Components and Attachments.
A webhook's username, avatar and text-to-speech setting can't be changed after a message is sent, so setting them on an edit throws.
Payloads
Strings, embeds and arrays of both are shorthand for a Payload. Build one directly for everything else, or to send the same message more than once:
Set AllowedMentions whenever the content includes user input. Without it, Discord's default applies and every mention in the text pings, @everyone included. AllowedMentions::none() silences them all. new AllowedMentions(users: [$userId], roles: true, everyone: false) lets through only what you list.
suppressEmbeds() hides link previews; on an edit, suppressEmbeds(false) brings them back. suppressNotifications() sends silently, and only applies to new messages.
Embeds
Up to 10 embeds can go in one message. Invalid colours and timestamps that can't be parsed throw when they're set. A string of only digits is read as a decimal colour, so prefix hex codes with #.
Threads and forum posts
Pass a thread ID to post into an existing thread. A Message remembers its thread, so edit() and delete() go to the right place:
When the webhook belongs to a forum or media channel, start a new post with a thread name and optional tags:
Files
Up to 10 files per message. $attachment->url() is the attachment:// reference embeds and components use to show an uploaded file. Files from a path are read when the request is sent, so queued messages don't hold them in memory.
When editing, Discord deletes every existing file that an upload doesn't list, including files that embeds and components show:
- Editing through a
Messagekeeps all of its files, including those embeds and components show, and adds the new ones. ->keepAttachments($id, …)keeps only those existing files.->clear(PayloadField::Attachments)removes all existing files; files added in the same edit replace them.- Editing by ID and uploading files without either of the above throws, since Discord would delete every existing file.
Edits that don't upload anything leave a message's files alone.
Components
Link buttons
Any webhook can send link buttons, up to five per row:
Interactive components (buttons that send events, select menus) only work on webhooks an application owns, and only that application receives the clicks. InterCord has no builders for them; send them as a RawComponent with Discord's component array.
Components V2
Discord's newer layout components replace content and embeds entirely:
InterCord sets the Components V2 flag for you. Content and embeds can't be combined with these components, so mixing them throws before anything is sent. Editing a message into Components V2 clears its content and embeds, which Discord requires. A message holds at most 40 components, counting nested ones.
In a Components V2 message, uploaded files only appear where a File, Thumbnail or MediaGallery shows them; a file nothing references is accepted but not shown. Once a message uses Components V2, Discord won't let an edit turn it off: editing through the Message keeps the flag for you, while an edit by ID that changes flags (such as suppressEmbeds()) is rejected by Discord.
Queues
QueuedWebhook sends payloads in order:
A payload that's still rate limited after every retry, or that gets no response, goes back on the front of the queue before the exception is rethrown, so run() resumes where it stopped. A payload Discord rejects is dropped, since sending it again would fail the same way.
Errors
Every exception InterCord throws implements Internet\InterCord\Exception\InterCordException:
| Exception | When |
|---|---|
DiscordApiException |
Discord answered with an error. Has $status, $discordCode and $errors. |
RateLimitedException |
Still rate limited after every retry. Extends DiscordApiException; has $retryAfter and $global. |
TransportException |
No response at all: DNS, connection, TLS or timeout. |
UnexpectedResponseException |
Discord reported success, but the response wasn't a valid message. |
InvalidArgumentException |
Something was rejected before sending. Subclasses: InvalidWebhookUrlException, InvalidColorException, InvalidTimestampException. |
DetachedMessageException |
edit() or delete() on a Message restored from serialised data. |
No exception message contains the webhook token. Client exceptions aren't chained, because their messages include the full URL.
Rate limits
InterCord waits out Discord's rate limits itself. It waits before a request when the previous one emptied the bucket. On a 429, it waits Discord's retry_after and tries again, up to maxRetries times (3 by default), before throwing RateLimitedException.
Configuration
Security
- The webhook token never appears in exception messages,
var_dump()orprint_r()output, or a serialisedMessage. Webhookrefuses to be serialised. Store the URL securely and rebuild withWebhook::fromUrl().- Report vulnerabilities privately; see SECURITY.md, which also covers verifying a release.
Contributing
See CONTRIBUTING.md. Releases are automated from conventional commits.
License
MIT
All versions of intercord with dependencies
ext-json Version *
guzzlehttp/guzzle Version ^7.9
guzzlehttp/psr7 Version ^2.7
psr/http-client Version ^1.0
psr/http-factory Version ^1.0
psr/http-message Version ^1.1 || ^2.0