Add Discord Bot Example using discord.py #48
Merged
+230
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 detailedREADME.mdx
tutorial that follows the established style of the cookbook.Type of Contribution
Checklist
README.mdx
file.requirements.txt
and.env.example
).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:
.env
files.discord.py
Cog.This saves developers time and provides a safe, working foundation they can trust and build upon.
External Links (if applicable):
Testing
The bot was tested by following the steps outlined in the
README.mdx
:requirements.txt
..env
file with a valid Discord token and Perplexity API key.python bot.py
locally./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.