
How to Create a Discord Paywall Bot with Stripe
Author
Josselin
Date Published
Introduction
Discord servers have become more than just communication platforms - they're thriving communities that often provide valuable content and services. As server owners look to monetize their communities, implementing a reliable paywall system becomes crucial. This is where our Stripe Discord bot comes in. It's free and open source.
Unlike traditional solutions like Donatebot.io, our bot communicates directly with Stripe, eliminating intermediary fees and providing a more streamlined experience for both server owners and users.
The Stack
1{[2 { name: 'Node.js', version: 'v16+' },3 { name: 'PostgreSQL', version: 'v13+' },4 { name: 'Discord.js', version: 'latest' },5 { name: 'Stripe API', version: 'latest' },6 { name: 'TypeORM', version: 'latest' },7 { name: 'Sentry', version: 'latest' }8]}
Features
Our free bot implements a robust subscription system that handles everything from user registration to subscription management:
- Instant role assignment upon subscription
- Email verification system with regex validation
- Support for both recurring and lifetime subscriptions
- Automated subscription status checks
- Progressive reminder system for expiring subscriptions
The Discord bot performs daily checks to ensure subscription validity and automatically manages user roles based on their subscription status.
User-friendly commands
We've designed an intuitive command system that makes it easy for users to manage their subscriptions. The bot supports both slash commands and traditional message commands:
1// Example of the subscribe command implementation2export const commands = [3 {4 name: "subscribe",5 description: "Subscribe or claim your active subscription!",6 options: [7 {8 name: "email",9 description: "Your email address",10 type: ApplicationCommandOptionType.String,11 required: false12 }13 ]14 }15];
The command system includes:
- /subscribe - Link your Discord account with a Stripe subscription
- /status - Check your subscription status
- /cancel - Cancel your subscription
- /admin-access - Manage admin access (admin only)
All commands are channel-restricted to maintain server organization. For example, subscription commands can only be used in designated channels.
Verification system
The bot includes a sophisticated verification system that runs daily checks:
1export const crons = [2 '0 0 1 * * *'3];45const getExpiredEmbed = (daysLeft: 0 | 1 | 2): EmbedBuilder => {6 const title = daysLeft > 0 ? 'Your subscription is about to expire' : 'Your subscription is expired';7 const embed = new EmbedBuilder()8 .setTitle(title)9 .setURL(process.env.STRIPE_PAYMENT_LINK)10 .setColor(process.env.EMBED_COLOR)11 .setDescription(`Please visit ${process.env.STRIPE_PAYMENT_LINK} to keep your exclusive access! ${daysLeft > 0 ? `Your subscription expires within ${daysLeft * 24} hours.` : ''}`);12 return embed;13}
Features:
- Daily subscription status verification
- Progressive reminder system (3 days, 2 days, 1 day before expiration)
- Automatic role management
- Detailed admin logging
- Support for lifetime subscriptions
Stripe integration
Our direct integration with Stripe ensures reliable payment processing:
1export const findSubscriptionsFromCustomerId = async (customerId: string) => {2 const subscriptions = await queue.add(async () =>3 await fetch(`https://api.stripe.com/v1/subscriptions?customer=${customerId}`, {4 headers: {5 Authorization: `Bearer ${process.env.STRIPE_API_KEY}`6 }7 }).json()8 );9 return subscriptions.data || [];10}1112export const findActiveSubscriptions = (subscriptions: any[]) => {13 return subscriptions.filter(sub =>14 sub.status === 'active' ||15 sub.status === 'trialing' ||16 (sub.cancel_at && sub.current_period_end > Date.now() / 1000)17 );18}
Installation
Setting up the bot is simple:
1. Install Node.js and PostgreSQL
2. Create and configure your database
3. Install dependencies:
4. Build the project:
5. Configure your environment variables:
6. Deploy using PM2 or your preferred process manager
Conclusion
Our Stripe Discord bot provides a powerful, secure, and efficient solution for implementing paywalls on Discord servers. Its direct integration with Stripe, automated verification system, and comprehensive admin controls make it an ideal choice for server owners looking to monetize their communities.
You can get the code on the source code on this link.