Skip to content

Add Discord Bot Example using discord.py #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 15, 2025

Conversation

AltF4Soul-JaY
Copy link
Contributor

Description

This pull request adds a new "Example" tutorial for creating a runnable Perplexity-powered Discord bot using discord.py. The example includes a self-contained bot script, configuration files, and a detailed README.mdx tutorial that follows the established style of the cookbook.

Type of Contribution

  • Example Tutorial
  • Showcase Project
  • Article/Integration Guide
  • Documentation Update
  • Bug Fix
  • Other (please describe)

Checklist

  • My code follows the cookbook's style guidelines.
  • I have included comprehensive documentation in the README.mdx file.
  • I have tested my code and it works as expected.
  • I have included all necessary dependencies and setup instructions (requirements.txt and .env.example).
  • My MDX file includes proper frontmatter (title, description, keywords).
  • I have linked to any external repositories or live demos.

Project Details

What problem does this solve?
This solves a common problem for Discord bot developers: how to easily and securely integrate a powerful, web-connected language model like Sonar into their bot. It bridges the gap between reading API documentation and having a practical, working application by providing a complete, runnable starting point.

What makes this contribution valuable to other developers?
It provides a high-quality, real-world example that goes beyond a basic API call. It demonstrates best practices for bot development, including:

  • Secure key management using .env files.
  • Clean project structure with a discord.py Cog.
  • Professional user-facing output via Discord embeds.
  • Essential features like permissions and error handling.
    This saves developers time and provides a safe, working foundation they can trust and build upon.

External Links (if applicable):

  • GitHub Repository: N/A
  • Live Demo: N/A
  • Blog Post/Article: N/A

Testing

The bot was tested by following the steps outlined in the README.mdx:

  1. Installed dependencies from requirements.txt.
  2. Created a .env file with a valid Discord token and Perplexity API key.
  3. Ran python bot.py locally.
  4. Invited the bot to a private Discord server.
  5. Successfully executed the /ask_perplexity command with an administrator account and received a valid, embedded response from the Sonar API.

Screenshots

https://cdn.discordapp.com/attachments/1400354826075770933/1400354826482880574/image.png?ex=68a01c0f&is=689eca8f&hm=10228fc0c809b3a626652a2f6051e0654acc2974b4efd556d7ed06699b4bccca&

Additional Notes

The permission system was intentionally kept simple (administrator-only) to ensure the example is focused on the Perplexity API and does not require an external database. This makes it more accessible for developers who are new to the platform.

@vikvang vikvang merged commit c0f3574 into perplexityai:main Aug 15, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants