Carbon Integration
The@saykit/carbon package provides seamless integration between Saykit and Carbon, a framework for building Discord bots. It enables command localization, guild-level language preferences, and automated translation of Discord command metadata.
Installation
Install both Saykit and the Carbon integration:Setup
1. Create Say Instance
First, create a Say instance with your supported locales:2. Register the Plugin
AddSayPlugin to your Carbon client:
SayPlugin registers the Say instance globally and applies extensions to interactions and guilds for easy access to localization utilities.
Localizing Commands
Use thewithSay higher-order function to create localized commands:
Command Properties
ThewithSay wrapper automatically localizes command properties based on Discord’s locale:
name- Command name (shown in slash command UI)description- Command descriptionoptions- Command option names, descriptions, and choicessubcommands- Subcommand metadatasubcommandGroups- Subcommand group metadata
Localizing Components
You can also localize Discord components like buttons, modals, and select menus:Button Component
Modal
Interaction Extensions
The Carbon integration extends Carbon’s interaction classes with asay property:
CommandInteractionAutocompleteInteractionComponentInteractionModalSubmitInteraction
Guild-Level Localization
Access guild-specific locale preferences:Message Formatting
Use ICU MessageFormat features with Carbon interactions:Pluralization
Select
Complete Example
Here’s a complete example of a localized Carbon bot:Type Safety
The Carbon integration maintains full TypeScript type safety:Best Practices
Pre-load All Locales
Pre-load All Locales
Load all locale messages at startup to avoid async issues during command registration:
Use Consistent Message IDs
Use Consistent Message IDs
Follow a naming convention for message IDs:
command.name.propertyfor command metadatacommand.name.message.typefor response messages
greet.name, greet.description, greet.message.successHandle Missing Translations
Handle Missing Translations
Always provide fallback text in your source locale to avoid runtime errors.
Test with Multiple Locales
Test with Multiple Locales
Use Discord’s language settings to test your bot in different locales during development.
API Reference
SayPlugin
withSay
- Accepts a Say instance and properties mapping function
- Automatically localizes command metadata for all supported locales
- Accepts localized property values
- Supports:
label,title,placeholder,content
Related
- React Integration - Use Saykit with React
- Babel Plugin - Configure the Babel transform
- Message Extraction - Extract translatable messages