Slash Command: /status
Relevant source files
The following files were used as context for generating this wiki page:The /status command is a user-facing slash command that allows a user to check their current live translation status within a specific guild. It provides feedback on whether they have translation enabled and, if so, what their selected target language is. This command is read-only; it retrieves information but does not alter any state. It works in conjunction with the /start and /stop commands, which control the user's translation settings.
The response to this command is ephemeral, meaning it is only visible to the user who executed it. This ensures that status checks do not clutter the chat channel.
Sources: src/commands/status.ts:1, README.md:15
Command Definition and Registration
The /status command is defined using the @discordjs/builders library, which provides a fluent API for creating slash command structures. The definition specifies the command's name and description.
Sources: src/commands/status.ts:6
// src/commands/status.ts:6
export const statusCommand = new SlashCommandBuilder().setName('status').setDescription('Show your current settings');
This command object is then collected along with all other bot commands and registered with the Discord API. This process happens either for a specific guild during development or globally for production use.
The following diagram illustrates the registration process for all slash commands, including /status.
This diagram shows how command definitions from various files are aggregated in interactions.ts and then sent to the Discord API for registration.
Sources: src/interactions.ts:11-17, src/app.ts:43-49
Command Execution Flow
When a user executes the /status command, the bot's main application file, app.ts, receives an interactionCreate event from Discord. A central router then dispatches this interaction to the appropriate handler, statusCommandHandler.
Sources: src/app.ts:20, src/app.ts:38
The handler's logic is as follows:
- Defer Reply: The handler first defers the reply with the
ephemeralflag set totrue. This tells Discord that a response is forthcoming but may take a moment to process, and that the final response should only be visible to the user. - Validation: It checks for the existence of
interaction.memberandinteraction.guildto ensure the command is being run in a valid guild context. - Fetch Settings: It retrieves the user's settings by calling
settingsStorage.get()with the currentguild.idanduser.id. - Conditional Response:
- If no settings are found (
prefsis null), it replies that live translation is not active. - If settings are found, it uses the stored target language key to look up the language's display name and icon from the
languagesobject and constructs a message indicating the active target language.
- If no settings are found (
Sources: src/commands/status.ts:8-24
The sequence diagram below visualizes the entire process.
This diagram shows the sequence of events from the user executing the command to receiving the ephemeral response.
Sources: src/app.ts:20-39, src/commands/status.ts:8-24
Possible Responses
The command provides one of two main responses based on the user's stored settings.
| Condition | Response Message |
|---|---|
| User has no active translation session. | You currently have not activated live translation! :sleeping: |
| User has an active translation session. | You are currently translating into <ICON> <LANGUAGE_NAME>! :thumbsup: |
Sources: src/commands/status.ts:17-23
Interaction with User Settings
The /status command is a consumer of data managed by the /start and /stop commands. The settingsStorage module acts as an abstraction layer for persisting user preferences.
- /start: When a user runs
/start <language>, thestartCommandHandlercallssettingsStorage.set(guild.id, user.id, targetLanguage)to save their choice. - /stop: When a user runs
/stop, thestopCommandHandlercallssettingsStorage.delete(guild.id, user.id)to remove their settings. - /status: This command calls
settingsStorage.get(guild.id, user.id)to read the data set by/start.
This relationship is illustrated below.
This diagram shows how the /start, /stop, and /status commands interact with the central settingsStorage.
Sources: src/commands/start.ts:36, src/commands/stop.ts:14, src/commands/status.ts:15
Summary
The /status command is a straightforward utility that enhances the user experience by providing clear, on-demand feedback about the bot's state for a specific user. By reading from a shared settingsStorage, it reflects the changes made by the /start and /stop commands, completing the core user-facing feature set for controlling translation sessions. Its use of ephemeral messages ensures that these status checks are private and do not add noise to server channels.
Sources: src/commands/status.ts, README.md