docs: Document SetApiView/SetApiModal in Shared API Keys guide #6803

Merged
ktriponis merged 4 commits from docs/apikeys-setapiview into V3/develop 2026-09-07 17:42:35 +02:00
ktriponis commented 2026-09-01 00:50:42 +02:00 (Migrated from github.com)

Adds a "Prompting for API Keys" section to the Shared API Keys guide, covering SetApiView / SetApiModal.

Closes #6114

Description of the changes

The guide only covers the [p]set api route and reading tokens back in code - nothing about SetApiView/SetApiModal in redbot.core.utils.views, which are a handy way to let a cog prompt the owner for keys via a secure button + modal instead of typing them in chat.

The new section covers:

  • SetApiView with default_service / default_keys to prompt for a service's keys
  • the modal's key value-per-line format, and that you keep the pre-filled key label (typing just the value gets rejected - this caught me out at first)
  • SetApiModal for embedding in a custom discord.ui.View
  • both being owner-only

Docs only, no code changes.

Have the changes in this PR been tested?

Yes

Adds a "Prompting for API Keys" section to the Shared API Keys guide, covering `SetApiView` / `SetApiModal`. Closes #6114 ### Description of the changes The guide only covers the `[p]set api` route and reading tokens back in code - nothing about `SetApiView`/`SetApiModal` in `redbot.core.utils.views`, which are a handy way to let a cog prompt the owner for keys via a secure button + modal instead of typing them in chat. The new section covers: - `SetApiView` with `default_service` / `default_keys` to prompt for a service's keys - the modal's `key value`-per-line format, and that you keep the pre-filled key label (typing just the value gets rejected - this caught me out at first) - `SetApiModal` for embedding in a custom `discord.ui.View` - both being owner-only Docs only, no code changes. ### Have the changes in this PR been tested? Yes
Flame442 (Migrated from github.com) requested changes 2026-09-01 03:23:59 +02:00
@ -48,6 +48,37 @@ Basic Usage
# Use the API key to access content as you normally would
Flame442 (Migrated from github.com) commented 2026-09-01 03:22:15 +02:00

I think [p]set api should be the "primary" way that users interface with the API key system, with the View already spawning from that command if no inputs are given (albeit without the service specific hints). Instead, I think the View is better used as a fallback included with the error message when the owner attempts to use a command requiring an API where the key has not been set. Adding an extra command in your cog that does the same thing as the existing command just bloats the bot with no real benefit, but dynamically responding to commands that fail due to missing keys can save a step for the owner.

Changing the example to that kind of setup would be more impactful.

I think `[p]set api` should be the "primary" way that users interface with the API key system, with the View already spawning from that command if no inputs are given (albeit without the service specific hints). Instead, I think the View is better used as a fallback included with the error message when the owner attempts to use a command requiring an API where the key has not been set. Adding an extra command in your cog that does the same thing as the existing command just bloats the bot with no real benefit, but dynamically responding to commands that fail due to missing keys can save a step for the owner. Changing the example to that kind of setup would be more impactful.
ktriponis (Migrated from github.com) reviewed 2026-09-01 10:57:33 +02:00
@ -48,6 +48,37 @@ Basic Usage
# Use the API key to access content as you normally would
ktriponis (Migrated from github.com) commented 2026-09-01 10:57:32 +02:00

Good point - I hadn't clocked that [p]set api already opens the modal when run bare, so a separate command really is just duplication. Reworked the example around the missing-key fallback instead: the command checks for the key and, if it isn't set, replies with the error plus the button so the owner can set it in place. Better fit, thanks!

Good point - I hadn't clocked that `[p]set api` already opens the modal when run bare, so a separate command really is just duplication. Reworked the example around the missing-key fallback instead: the command checks for the key and, if it isn't set, replies with the error plus the button so the owner can set it in place. Better fit, thanks!
Flame442 (Migrated from github.com) requested changes 2026-09-07 17:33:43 +02:00
Flame442 (Migrated from github.com) left a comment

Attempting to make some things render nicer

Attempting to make some things render nicer
@ -48,6 +48,37 @@ Basic Usage
# Use the API key to access content as you normally would
Flame442 (Migrated from github.com) commented 2026-09-07 17:25:13 +02:00
`SetApiView` is most useful as a fallback when a required key is missing. When a command needs a key that has not been set, a reply with the error message that includes this view will include a button that allows the owner to instantly open the secure modal. The parameters ``default_service`` and ``default_keys`` can be configured to pre-fill the modal with the service and key names the cog expects.
```suggestion `SetApiView` is most useful as a fallback when a required key is missing. When a command needs a key that has not been set, a reply with the error message that includes this view will include a button that allows the owner to instantly open the secure modal. The parameters ``default_service`` and ``default_keys`` can be configured to pre-fill the modal with the service and key names the cog expects. ```
Flame442 (Migrated from github.com) commented 2026-09-07 17:26:49 +02:00
            if tokens.get("api_key") is None:
```suggestion if tokens.get("api_key") is None: ```
Flame442 (Migrated from github.com) commented 2026-09-07 17:27:49 +02:00
``default_service`` pre-fills and locks the service name. ``default_keys`` is a mapping of the key names the service expects (values may be empty) and pre-populates the modal. The owner enters one ``key value`` pair per line, keeping the key label; for the example above the field is pre-filled with ``api_key YOUR_API_KEY``, and replacing the line with just the value is rejected. On submit the tokens are saved with `Red.set_shared_api_tokens`.
```suggestion ``default_service`` pre-fills and locks the service name. ``default_keys`` is a mapping of the key names the service expects (values may be empty) and pre-populates the modal. The owner enters one ``key value`` pair per line, keeping the key label; for the example above the field is pre-filled with ``api_key YOUR_API_KEY``, and replacing the line with just the value is rejected. On submit the tokens are saved with `Red.set_shared_api_tokens`. ```
Flame442 (Migrated from github.com) commented 2026-09-07 17:33:05 +02:00
To embed the prompt in a custom `discord.ui.View`, use `SetApiModal` directly and send it with ``interaction.response.send_modal(...)``. `SetApiView` and `SetApiModal` are both owner-only.
```suggestion To embed the prompt in a custom `discord.ui.View`, use `SetApiModal` directly and send it with ``interaction.response.send_modal(...)``. `SetApiView` and `SetApiModal` are both owner-only. ```
Flame442 (Migrated from github.com) approved these changes 2026-09-07 17:42:23 +02:00
Flame442 (Migrated from github.com) left a comment

Thank you for contributing!

Thank you for contributing!
Sign in to join this conversation.
No reviewers
No labels
Automated PR
Blocked
Blocked By: Damage Control
Blocked By: Dependency
Blocked By: Other PR
Breaking Change
Category: CI
Category: Cogs - Admin
Category: Cogs - Alias
Category: Cogs - Audio
Category: Cogs - Bank
Category: Cogs - Cleanup
Category: Cogs - CustomCommands
Category: Cogs - Dev
Category: Cogs - Downloader
Category: Cogs - Economy
Category: Cogs - Filter
Category: Cogs - General
Category: Cogs - Image
Category: Cogs - Mod
Category: Cogs - Modlog
Category: Cogs - Mutes
Category: Cogs - Permissions
Category: Cogs - Reports
Category: Cogs - Streams
Category: Cogs - Trivia
Category: Cogs - Trivia - Lists
Category: Cogs - Warnings
Category: Core - API - App Commands Package
Category: Core - API - Audio
Category: Core - API - Bank
Category: Core - API - Commands Package
Category: Core - API - Config
Category: Core - API - Other
Category: Core - API - Utils Package
Category: Core - Bot Class
Category: Core - Bot Commands
Category: Core - Command-line Interfaces
Category: Core - Downloader
Category: Core - Help
Category: Core - i18n
Category: Core - Modlog
Category: Core - Other Internals
Category: Core - RPC/ZMQ
Category: Docker
Category: Docs - Changelogs
Category: Docs - For Developers
Category: Docs - Install Guides
Category: Docs - Other
Category: Docs - User Guides
Category: Meta
Category: RPC/ZMQ methods
Category: Vendored Packages
Changelog Entry: Added
Changelog Entry: Pending
Changelog Entry: Skipped
Closed: Duplicate
Closed: External
Closed: Invalid
Closed: User Error
Closed: Won't Fix
Complex Issue
Docs-only
Feature Branch
Good First Issue
Help Wanted
High Priority
Needs Backport To stable-docs
No Activity
No Repro
QA: Bypassed
QA: Changes Requested
QA: Passed
Release Blocker
Status: Accepted
Status: Frozen
Status: In Progress
Status: Needs Discussion
Status: Needs Info
Status: Needs Triage
Status: PRs Welcome
Type: Bug
Type: Dependency Update
Type: Deprecation
Type: Enhancement
Type: Feature
Type: Informational
Type: Merge
Type: Optimisation
Type: Question
Type: Removal
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Mrcoolgamer11/Red-DiscordBot!6803
No description provided.