Download the PHP package mhhidayat/php-discord-client without Composer

On this page you can find all versions of the php package mhhidayat/php-discord-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-discord-client

PHP Discord Client

A comprehensive PHP library for interacting with Discord via both webhooks and bot API. Send messages, rich embeds, and manage Discord communications with an elegant, fluent interface.

Features

Requirements

Dependencies

This library includes:

Installation

Install via Composer:

Quick Start

Basic Usage

Webhook Messages

Send messages using Discord webhooks:

Bot Messages

Send messages using a Discord bot token:

Rich Embeds with Builder

Use the fluent embed builder for creating rich embeds with both webhooks and bots:

Custom Content with Raw Arrays

You can use raw arrays for custom content with both webhooks and bots:

Customize Username and Avatar

Customize the appearance of your messages (webhooks support username/avatar override, bots use their configured identity):

Text-to-Speech (TTS)

Enable TTS for your messages with both webhooks and bots:

Webhooks vs Bots

When to Use Webhooks

Webhooks are perfect for:

When to Use Bots

Bots are ideal for:

Setup Requirements

Webhooks:

  1. Create a webhook in your Discord server settings
  2. Copy the webhook URL
  3. Start sending messages immediately

Bots:

  1. Create a bot application in Discord Developer Portal
  2. Generate and copy the bot token
  3. Invite the bot to your server with appropriate permissions
  4. Get the channel ID where you want to send messages
  5. Use the bot token and channel ID in your code

Advanced Usage

Advanced Embed Fields with Builder

For more complex field management, you can use the EmbedsFieldsContract:

Video Embeds

Include video content in your embeds:

Embed Builder Features

The embed builder provides a fluent interface for creating rich embeds:

Available Colors Enum

The library includes a comprehensive Colors enum with Discord's official colors:

Conditional Sending

Send messages only when a condition is met:

Custom Headers

Custom Timeout

Default timeout is 15 seconds. You can customize it:

Dynamic Content with Closures

Check Response Status

Security Best Practices

Environment Variables

Store sensitive information like bot tokens and webhook URLs in environment variables:

Token Security

API Reference

Common Methods (Both DiscordWebhook and DiscordBot)

make(): self

Create a new instance of the Discord client.

text(string $text): self

Set a simple text message (max 2000 characters).

setContent(array|Closure $content): self

Set custom content including embeds. Accepts an array or closure that returns an array.

addEmbeds(Closure $embedsHandler): self

Add rich embeds using the fluent EmbedsContract builder. The closure receives an EmbedsContract instance.

allowTTS(): self

Enable text-to-speech for the message.

send(): self

Send the message to Discord.

sendWhen(bool|Closure $condition): self

Send the message only if the condition is true.

successful(): bool

Check if the last request was successful (HTTP 2xx).

failed(): bool

Check if the last request failed.

getResponseJson(): string

Get the raw JSON response from Discord.

Webhook-Specific Methods (DiscordWebhook)

setWebhookURL(string $url): self

Set the Discord webhook URL (required for webhooks).

setUsername(string $username): self

Override the default webhook username.

setAvatar(string $avatarURL): self

Override the default webhook avatar.

Bot-Specific Methods (DiscordBot)

setBotToken(string $token): self

Set the Discord bot token (required for bots).

setChannelID(string $channelID): self

Set the target channel ID where the bot will send messages (required for bots).

Static Methods (Both Classes)

withHeaders(array $headers): self

Create instance with custom HTTP headers.

timeout(int $seconds): self

Create instance with custom timeout (default: 15 seconds).

withConfig(array $config): self

Create instance with configuration array.

Embed Builder Methods

The EmbedsContract provides these methods for building rich embeds:

title(string $title): self

Set the embed title.

description(string $description): self

Set the embed description.

url(string $url): self

Set the embed URL (makes the title clickable).

color(Colors|int $color): self

Set the embed color using the Colors enum or a custom integer.

enableTimestamp(): self

Add the current timestamp to the embed.

authorName(string $authorName): self

Set the author name.

authorUrl(string $authorUrl): self

Set the author URL (makes the author name clickable).

authorIconUrl(string $authorIconUrl): self

Set the author icon URL.

footerText(string $footerText): self

Set the footer text.

footerIconUrl(string $footerIconUrl): self

Set the footer icon URL.

imageUrl(string $imageUrl): self

Set the embed image URL (must be HTTPS).

imageWidth(int $width): self

Set the embed image width in pixels.

imageHeight(int $height): self

Set the embed image height in pixels.

thumbnailUrl(string $thumbnailUrl): self

Set the embed thumbnail URL.

thumbnailWidth(int $width): self

Set the embed thumbnail width in pixels.

thumbnailHeight(int $height): self

Set the embed thumbnail height in pixels.

providerName(string $providerName): self

Set the embed provider name.

providerUrl(string $providerUrl): self

Set the embed provider URL.

Embed Fields Builder Methods

The EmbedsFieldsContract provides these methods for building embed fields:

name(string $name): self

Set the field name. Must be called before value() and inline().

value(string $value): self

Set the field value. Must be called after name().

inline(bool $inline): self

Set whether the field should be displayed inline. Must be called after name().

build(): array

Build and return the fields array (used internally).

fields(array|Closure $fields): self

Add fields to the embed (max 25 fields). Each field should have 'name', 'value', and optionally 'inline' keys. Accepts either an array or a closure with EmbedsFieldsContract for more control.

videoUrl(string $videoUrl): self

Set the embed video URL.

videoWidth(int $width): self

Set the embed video width in pixels.

videoHeight(int $height): self

Set the embed video height in pixels.

Error Handling

The library throws DiscordClientException for validation errors:

Common validation errors:

Examples

Notification System

Error Logging

Deployment Notifications

Rich Media Embeds

Showcase images and thumbnails in your embeds:

Product Showcase

Perfect for e-commerce or product announcements:

Troubleshooting

Common Issues

"Webhook URL is not set" Error

"No content is set" Error

Bot Messages Not Sending

Webhook Messages Not Appearing

Debug Response

Check the response from Discord for debugging:

License

See LICENSE for details.

Author

mhhidayat - [email protected]


All versions of php-discord-client with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0
vlucas/phpdotenv Version ^5.6
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package mhhidayat/php-discord-client contains the following files

Loading the files please wait ...