Integrate Your Website with Discord: Notifications, Bots, OAuth2
You set up a Discord webhook, but notifications arrive late or not at all. Or OAuth2 returns an invalid scope error. These issues arise from misconfiguration or ignoring API rate limits. We solve such tasks daily — full Discord API integration with your site. Stack: Laravel 11, PHP 8.3, PostgreSQL, Redis. We automate notifications via webhooks, implement login via Discord (OAuth2), and role-gating for access control. Order an integration — prices start from $500 for basic webhook setup, up to $2500 for a full bot with custom logic. Cost is finalized after analysis.
Problems We Solve
Manual notification sending — an admin copies announcements by hand, forgets, or makes mistakes. Automation via webhooks eliminates human error. Complex authorization — users need to remember logins and passwords. OAuth2 via Discord simplifies login to one click. Role-gating — you need to give paid subscribers access to restricted sections. Discord API checks the user's role and dynamically grants access. Typical technical mistakes: incorrect scope in OAuth2, missing rate limit handling (50 requests per second), token leakage through logs or client code. Webhooks are set up 10 times faster than a bot, but a bot provides 5 times more capabilities — from automatic role assignment to moderation.
How to Avoid Common Errors When Integrating the Discord API
First mistake — incorrect scope. To get the user's email, always specify identify. To check roles, use guilds.members.read. Second — storing the Client Secret. It must be server-side only, never exposed in client code. Third — exceeding rate limits. Discord limits 50 requests per second per token. Use a queue (Redis) to send webhooks asynchronously. Fourth — wrong OAuth2 flow order: first exchange the code for a token, then use the token to fetch data. Do not mix stages.
How We Do It
We use the stack: Laravel 11 (PHP 8.3) for backend, MySQL/PostgreSQL, Docker for environment. Below is an example of webhook implementation for notifications:
class DiscordNotifier
{
public function send(string $webhookUrl, array $embeds): void
{
Http::post($webhookUrl, [
'embeds' => $embeds,
]);
}
public function announceNewArticle(Article $article): void
{
$this->send(config('services.discord.news_webhook'), [[
'title' => $article->title,
'description' => $article->excerpt,
'url' => route('articles.show', $article->slug),
'color' => 0x5865F2, // Discord Blurple
'image' => ['url' => $article->cover_url],
'timestamp' => $article->published_at->toIso8601String(),
'footer' => ['text' => 'My Site'],
]]);
}
}
We configure a queue (via Redis) to process webhooks asynchronously, so as not to block the user's response.
How the OAuth2 Flow Works
OAuth2 is a standard authorization protocol that allows users to log in via third-party services (OAuth 2.0). In the case of Discord:
- Register an application in the Discord Developer Portal and get a Client ID and Client Secret.
- Set up a redirect URI to your site.
- When the user clicks "Login with Discord", they are redirected to authorization, then back with a code.
- The server exchanges the code for a token and fetches the user's data.
Example routes in Laravel:
Laravel OAuth2 Routes
Route::get('/auth/discord/redirect', function () {
return redirect(
'https://discord.com/api/oauth2/authorize?' .
http_build_query([
'client_id' => config('services.discord.client_id'),
'redirect_uri' => route('auth.discord.callback'),
'response_type' => 'code',
'scope' => 'identify guilds.members.read',
])
);
});
Route::get('/auth/discord/callback', function (Request $request) {
// Exchange code for token
$tokenResp = Http::post('https://discord.com/api/oauth2/token', [
'client_id' => config('services.discord.client_id'),
'client_secret' => config('services.discord.client_secret'),
'code' => $request->code,
'grant_type' => 'authorization_code',
'redirect_uri' => route('auth.discord.callback'),
])->json();
// Fetch user data
$user = Http::withToken($tokenResp['access_token'])
->get('https://discord.com/api/users/@me')
->json();
// Check membership in server
$member = Http::withToken($tokenResp['access_token'])
->get("https://discord.com/api/users/@me/guilds/{$guildId}/member")
->json();
return redirect('/dashboard');
});
Choosing Between Webhooks and a Bot for Your Project
Webhooks are suitable for sending notifications: new articles, orders, registrations. They are simple to set up and do not require a persistent connection. Bots (Gateway API) are needed for interactive scenarios: role assignment, moderation, integration with external services. For example, a bot can automatically assign a premium role after payment on the site. If you only need notifications — go with webhooks. If two-way interaction is required — choose a bot. We help you decide during the analysis phase.
Work Process
| Stage | Description | Duration |
|---|---|---|
| Analysis | We study your architecture, identify integration points | 1 day |
| Design | Create OAuth2 scheme, configure webhooks | 1 day |
| Implementation | Write code, deploy middleware, test limits | 2–3 days |
| Testing | Verify notifications correctness, error handling | 1 day |
| Deployment | Move to production, set up monitoring | 1 day |
Total: from 3 to 7 days depending on complexity.
What's Included
- Setting up Discord Webhooks for notifications (new articles, orders, registrations).
- Implementing OAuth2 authorization with role checking.
- Developing a bot for automatic role assignment.
- Integration documentation and post-launch support.
- 30-day guarantee of functionality and bug fixes.
Comparison of Integration Methods
| Method | Purpose | Complexity | Speed |
|---|---|---|---|
| Webhooks | Notifications | Low | 1 day |
| OAuth2 | Authorization | Medium | 3–4 days |
| Bot (Gateway API) | Interactive scenarios | High | 5–7 days |
Our team has over 10 years of experience in web development and dozens of successful Discord integrations. We guarantee stable operation and timely API updates. The time saved on manual notifications pays off within the first weeks. Get a consultation — contact us to discuss details. Order an integration, and we'll set it all up for your site.







