PHP code example of reysa / discord-api

1. Go to this page and download the library: Download reysa/discord-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

reysa / discord-api example snippets


DAPI::sendMessageToChannel($channelId, ['content' => 'Hello from Laravel!']);
DAPI::giveRole($userId, [$roleId]);
DAPI::getGuildChannels($guildId);


return [
    'bot_token' => env('DISCORD_BOT_TOKEN'),
    'guild_id'  => env('GUILD_ID'),
];
~~~

Then set the values in your `.env` file:

~~~env
DISCORD_BOT_TOKEN=your_bot_token_here
GUILD_ID=your_guild_id_here
~~~

---

## Quick Usage Example

The package ships with a facade alias `DAPI`.

~~~php


use Reysa\DiscordAPI\Facades\DAPI;
use Illuminate\Support\Facades\Route;

Route::get('/test-discord', function () {
    DAPI::sendMessageToChannel(
        '123456789012345678',
        ['content' => 'Hello from Reysa Discord API!']
    );

    return 'Message sent (if token and channel are correct).';
});
~~~

> **Note:** For methods like `sendMessageToChannel` and `sendEmbedMessageToUser`,  
> the second argument is the raw payload array that Discord accepts  
> (for example: `['content' => '...']`, `['embeds' => [...]]`, etc).  
> In v1 this payload is passed directly to the HTTP request body without additional validation.

---

## Full API coverage

~218 methods total. Request bodies for POST/PUT/PATCH calls are passed through to Discord as-is
(no field validation) — see the linked official docs page per category for the exact payload
shape, or browse it interactively in Swagger (below).

| Category | Methods | Source file | Official docs |
|---|---|---|---|
| Core helpers (v1) | 14 | `src/DAPI.php` | — |
| Guilds (settings, members, roles, bans, widgets, onboarding) | 40 | `Concerns/InteractsWithGuilds.php` | [Guild](https://discord.com/developers/docs/resources/guild) |
| Channels (CRUD, permissions, threads, pins, invites) | 24 | `Concerns/InteractsWithChannels.php` | [Channel](https://discord.com/developers/docs/resources/channel) |
| Application Commands (slash commands) | 16 | `Concerns/InteractsWithApplicationCommands.php` | [Application Commands](https://discord.com/developers/docs/interactions/application-commands) |
| Webhooks | 15 | `Concerns/InteractsWithWebhooks.php` | [Webhook](https://discord.com/developers/docs/resources/webhook) |
| Messages (send, edit, delete, react, bulk-delete, pins) | 14 | `Concerns/InteractsWithMessages.php` | [Message](https://discord.com/developers/docs/resources/message) |
| Users | 12 | `Concerns/InteractsWithUsers.php` | [User](https://discord.com/developers/docs/resources/user) |
| Emojis | 10 | `Concerns/InteractsWithEmojis.php` | [Emoji](https://discord.com/developers/docs/resources/emoji) |
| Monetization (SKUs, entitlements, subscriptions) | 8 | `Concerns/InteractsWithMonetization.php` | [SKU](https://discord.com/developers/docs/resources/sku) |
| Interactions (responding/following up) | 8 | `Concerns/InteractsWithInteractions.php` | [Receiving & Responding](https://discord.com/developers/docs/interactions/receiving-and-responding) |
| Stickers | 8 | `Concerns/InteractsWithStickers.php` | [Sticker](https://discord.com/developers/docs/resources/sticker) |
| Soundboard | 7 | `Concerns/InteractsWithSoundboard.php` | [Soundboard](https://discord.com/developers/docs/resources/soundboard) |
| Guild Scheduled Events | 6 | `Concerns/InteractsWithScheduledEvents.php` | [Guild Scheduled Event](https://discord.com/developers/docs/resources/guild-scheduled-event) |
| Guild Templates | 6 | `Concerns/InteractsWithGuildTemplates.php` | [Guild Template](https://discord.com/developers/docs/resources/guild-template) |
| Auto Moderation | 5 | `Concerns/InteractsWithAutoModeration.php` | [Auto Moderation](https://discord.com/developers/docs/resources/auto-moderation) |
| Voice | 5 | `Concerns/InteractsWithVoice.php` | [Voice](https://discord.com/developers/docs/resources/voice) |
| Invites | 4 | `Concerns/InteractsWithInvites.php` | [Invite](https://discord.com/developers/docs/resources/invite) |
| Stage Instances | 4 | `Concerns/InteractsWithStageInstances.php` | [Stage Instance](https://discord.com/developers/docs/resources/stage-instance) |
| Applications | 3 | `Concerns/InteractsWithApplications.php` | [Application](https://discord.com/developers/docs/resources/application) |
| OAuth2 (code exchange, refresh, revoke, authorization URL) | 6 | `Concerns/InteractsWithOAuth2.php` | [OAuth2](https://discord.com/developers/docs/topics/oauth2) |
| Polls | 2 | `Concerns/InteractsWithPolls.php` | [Poll](https://discord.com/developers/docs/resources/poll) |
| Audit Log | 1 | `Concerns/InteractsWithAuditLog.php` | [Audit Log](https://discord.com/developers/docs/resources/audit-log) |

Method names mirror Discord's own endpoint titles (e.g. "Get Guild Channels" →
`getGuildChannels()`), so if you know the Discord docs, you already know the method name.

---

## Browsable docs & live testing (Swagger)

Every method above is also documented interactively — grouped by category, with the real PHP
call signature front and center, Discord's own description, and (where available) a real
example payload — plus a "Try it out" button that fires a real request against your own bot.



- **`http://localhost:8081`** — Swagger UI.
- **`http://localhost:8080`** — the harness Laravel app itself (