Team Commsvendor:discordEmail OTPUnwrapped Magic LinkCarrier SMS DIDCloud KMS TOTP
Automate Discord New Login Location & 2FA in Playwright & Stagehand
Automate Discord New Login Location IP-authorization links (unwrapped from SendGrid trackers), email codes, SMS OTPs, and TOTP.
1. 60-Second Gmail & Outlook Auto-Forwarding Filter
Don't want to change your existing account email on Discord? Keep your corporate inbox on Discord and forward only verification emails to <identity-slug>@in.sentryrelay.com. Sentry Relay's Stage 2 unwrapper preserves the original Discord sender header automatically (full setup guide).
# Paste into Gmail -> Settings -> Filters -> Create a new filter ("Has the words")
from:(discord.com OR discordapp.com) ("New Login Location" OR "Authorize IP" OR "security code" OR "verification code")
# Action: Forward it to -> <your-identity-slug>@in.sentryrelay.com2. Copy-Paste Discord 2FA Automation Snippets
Choose your browser automation stack below. All snippets resolve codes in <200ms with Upstash Redis 15-second lookback protection so arrived-before-wait race conditions never fail a run.
import { test, expect } from '@playwright/test';
import { SentryRelay } from '@sentryrelay/sdk';
const relay = new SentryRelay({ apiKey: process.env.SENTRY_RELAY_API_KEY! });
test('Discord cloud login with New Login Location IP approval + TOTP', async ({ page }) => {
await page.goto('https://discord.com/login');
await page.fill('input[name="email"]', process.env.DISCORD_EMAIL!);
await page.fill('input[name="password"]', process.env.DISCORD_PASSWORD!);
await page.click('button[type="submit"]');
// Discord blocks cloud IPs with "New Login Location Detected" email
const ipWarning = page.locator('text=New login location detected');
if (await ipWarning.isVisible({ timeout: 5000 }).catch(() => false)) {
const auth = await relay.wait('discord-bot', { sender: 'discord', timeout: 30 });
if (auth.event?.magicLink) {
await page.goto(auth.event.magicLink);
await page.click('button:has-text("Authorize IP")');
await page.goto('https://discord.com/login');
}
}
// Handle Discord Authenticator TOTP if enabled
const mfaInput = page.locator('input[placeholder*="6-digit"]');
if (await mfaInput.isVisible({ timeout: 4000 }).catch(() => false)) {
const token = await relay.totp.get('discord-bot', 'discord_totp');
await mfaInput.fill(token.code);
await page.click('button[type="submit"]');
}
await expect(page).toHaveURL(/discord\.com\/channels/);
});3. Discord Production Gotchas
Cloud Browsers Almost Always Trip "New Login Location"
Running Playwright inside Browserbase, AWS, or GCP immediately triggers Discord's IP verification email. Sentry Relay unwraps Discord's `click.discord.com` wrapper and returns the direct `/authorize-ip` target.
Re-Submitting Login After Authorizing IP
After clicking "Authorize IP" on Discord's verification page, navigate back to `discord.com/login` (or retry submitting credentials) so the now-whitelisted IP proceeds to TOTP/workspace.
Missed Message & Nitro Digests Filtered Out
Discord's digest and billing receipts are disqualified by `vendor:discord` so your agent only receives genuine login/IP verification events.