Skip to main content

Python Prompt to Build a Slack or Discord Bot with Commands and Tasks

Build a Python Slack or Discord bot with slash commands, interactive messages, scheduled tasks and external API integrations.

Fill in the placeholders

Edit the values, then copy your finished prompt.

Your Prompt
prompt.txt
Build a Slack bot in Python for a software engineering team of 50 developers team. The bot should automate deployment status reporting, manage on-call rotations, and surface CI/CD metrics and handle 30 concurrent users. Use Python 3.12 with slack-bolt. Implement these features: 1) Set up the bot application structure: create a modular architecture with separate files for commands, events, tasks, and services. Configure OAuth 2.0 with bot and user token scopes authentication, implement proper token storage using environment variables, and set up logging with INFO with DEBUG available via env flag level. Handle the bot lifecycle: startup initialization, graceful shutdown, and automatic reconnection on disconnect. 2) Implement 8 slash commands: for each command, define the name, description, required parameters with type validation, optional parameters with defaults, and permission requirements. Commands should include: /deploy-status, /oncall, /incident, /metrics, /standup, /remind, /config, /help. Add command cooldowns of 5 seconds per user to prevent spam. 3) Build interactive message components: create messages with buttons, dropdown selects, modal forms, and date pickers that respond to user interactions. Implement a conversation flow for incident creation (severity > description > affected services > notification channels) using a state machine pattern that tracks user progress and expires after 10 minutes. 4) Create scheduled tasks using APScheduler: implement daily standup reminder (9am), weekly metrics digest (Monday 10am), deployment window notifications that run at specified intervals, can be enabled/disabled per channel, and report execution results. Store task state in SQLite with SQLAlchemy to survive restarts. 5) Integrate with external APIs: build a service layer that connects to GitHub Actions, PagerDuty, and Datadog, caches responses for 5 minutes, handles API rate limits and errors gracefully, and formats results into rich embeds or Block Kit messages. 6) Add an admin system: define bot-admin (full access) and team-lead (channel management) with escalating permissions, create admin-only commands for bot management (reload config, view stats, manage channels), and implement an audit log for administrative actions. 7) Write error handling: catch and log all unhandled exceptions without crashing, send user-friendly error messages, and create a #bot-errors error reporting channel for the development team.

What this prompt does

This prompt builds a [platform] bot in Python for a [team_type], designed to [bot_purpose] and handle [expected_users] concurrent users. It lays out a modular architecture and works through the parts that actually matter in production: lifecycle handling with reconnection, [command_count] slash commands with cooldowns, interactive components with a state machine, scheduled tasks that survive restarts, external API integration, an admin system with an audit log, and robust error handling. The emphasis on reconnects, cooldowns, and persistent state is what separates a real ops tool from a toy.

The variables define the bot's surface and resilience. [bot_framework] and [auth_method] set the foundation, [command_count] and [primary_commands] define the command set with [cooldown_duration] rate limiting, and [interactive_elements] plus [conversation_flow] drive multi-step interactions via a state machine that expires after [session_timeout]. [scheduler_library], [scheduled_tasks], and [storage_backend] handle recurring jobs whose state outlives restarts, while [external_apis] and [admin_roles] cover integrations and permissions.

When to use it

  • Building an internal Slack or Discord bot to offload repetitive ops work.
  • Implementing slash commands with per-user [cooldown_duration] cooldowns to prevent spam.
  • Driving multi-step flows like incident creation with a state machine that expires.
  • Running scheduled jobs whose state survives bot restarts via [storage_backend].
  • Integrating external services like [external_apis] with caching and rate-limit handling.
  • Adding an admin system with [admin_roles] and an audit log for accountability.

Example output

You get a modular bot implementation with code: a project structure separating commands, events, tasks, and services; lifecycle handling with [auth_method] auth, graceful shutdown, and auto-reconnection; [command_count] slash commands ([primary_commands]) with type validation and [cooldown_duration] cooldowns; interactive components using [interactive_elements] and a state machine for [conversation_flow] expiring after [session_timeout]; [scheduler_library] jobs for [scheduled_tasks] with state in [storage_backend]; a service layer integrating [external_apis] with caching; an admin system with [admin_roles] and an audit log; and error handling routing failures to [error_channel].

Pro tips

  • Make auto-reconnection non-negotiable; a bot that dies on a brief disconnect is useless for ops, so the lifecycle step must handle it.
  • Add [cooldown_duration] cooldowns to every command in [primary_commands]; without them, one impatient user can spam your integrations.
  • Persist state to [storage_backend] so [scheduled_tasks] and in-flight [conversation_flow] sessions survive a restart instead of vanishing.
  • Cache [external_apis] responses for the configured duration and handle their rate limits, or the bot will get throttled under load.
  • Keep an audit log of admin actions; for a bot wired into deployments and on-call, accountability is essential.
  • Set a [session_timeout] on multi-step flows so abandoned conversations clean themselves up instead of lingering.
  • Route unhandled exceptions to [error_channel] with friendly user-facing messages, so the bot never crashes silently and the team sees failures fast.

Frequently Asked Questions

Does this work for both Slack and Discord?
Yes. The `[platform]` variable selects the target, defaulting to Slack with slack-bolt. The architecture, command, scheduling, and admin patterns transfer to Discord, though you swap the `[bot_framework]` and adjust the platform-specific interaction APIs accordingly.
How does the bot survive restarts without losing state?
Scheduled task state and in-progress conversations are stored in `[storage_backend]` rather than memory. So when the bot restarts, `[scheduled_tasks]` resume on schedule and the audit log persists, which is the difference between a durable tool and a fragile prototype.
What stops users from spamming commands?
Each command enforces a `[cooldown_duration]` per-user cooldown. This prevents a single user from hammering integrations like `[external_apis]`, which both protects downstream rate limits and keeps the bot responsive for everyone else on the team.
How are multi-step interactions handled?
Through a state machine that tracks user progress across steps, such as the `[conversation_flow]` incident creation flow. Sessions expire after `[session_timeout]` so abandoned interactions clean up automatically rather than leaving the bot waiting on input that never arrives.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

More in Python & Automation Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

AI assistant · trained on my work

👋

Hey there!

Quick Actions

WhatsApp Direct line to me

Chat on WhatsApp

+880 1723 741224 · Replies within the hour on working days

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

mejba.13@gmail.com

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support