Slash Command: /stop
Relevant source files
The following files were used as context for generating this wiki page:The /stop command is a user-facing slash command that deactivates the live voice translation service for the user who invokes it within a specific guild. Its primary function is to remove the user's translation settings, effectively ending their translation session without affecting other users or the bot's presence in the voice channel. This command is the direct counterpart to the /start command, which initiates the translation service for a user.
The command operates by deleting the user's specific settings from a persistent storage, which is checked during the voice processing pipeline. Once the settings are removed, the bot will no longer attempt to translate that user's speech. The user receives an ephemeral confirmation message upon successful deactivation.
Sources: src/commands/stop.ts, README.md:15, src/commands/start.ts
Command Definition
The /stop command is defined using the @discordjs/builders library. It is a simple command with no options or arguments.
| Property | Value |
|---|---|
| Name | stop |
| Description | Stop the translation |
| Arguments | None |
Sources: src/commands/stop.ts:5
The command's JSON definition is exported and aggregated with other commands for deployment to Discord's API.
// src/commands/stop.ts:5
export const stopCommand = new SlashCommandBuilder().setName('stop').setDescription('Stop the translation');
// src/interactions.ts:12
const commands = [
// ... other commands
stopCommand.toJSON()
];
Sources: src/commands/stop.ts:5, src/interactions.ts:12
Execution Flow
When a user executes the /stop command, the bot's interactionCreate event listener in app.ts routes the interaction to the stopCommandHandler. The handler then performs the necessary logic to deactivate translation for the user.
This sequence diagram illustrates the complete flow from user action to final confirmation.
Sources: src/app.ts:20, 42, src/commands/stop.ts:7-24
Command Handler Logic
The core logic resides in the stopCommandHandler function.
- Defer Reply: It first calls
interaction.deferReply({ ephemeral: true })to acknowledge the command immediately and send subsequent responses as hidden (ephemeral) messages. This prevents the command from timing out. - Validation: It checks if the
interactionobject contains validmemberandguildproperties. If not, it replies with a generic error. - Delete Settings: The central action is
settingsStorage.delete(interaction.guild.id, interaction.user.id). This removes the user's settings, which were previously set by the/startcommand. The settings link a user ID within a guild to a target translation language. - Confirmation: Upon successful deletion, it sends a final confirmation message:
Live translation deactivated! :sleeping:. - Error Handling: A
try...catchblock wraps the deletion logic to catch any potential errors fromsettingsStorageand reply with an error message if the operation fails.
// src/commands/stop.ts:7-24
export const stopCommandHandler: CommandHandler = async (interaction) => {
await interaction.deferReply({ ephemeral: true });
if (!interaction.member || !interaction.guild) {
await interaction.editReply('An error occurred! :grimacing:');
return;
}
try {
await settingsStorage.delete(interaction.guild.id, interaction.user.id);
} catch (err) {
console.error(err);
await interaction.editReply('An error occurred! :grimacing:');
}
await interaction.editReply('Live translation deactivated! :sleeping:');
};
Sources: src/commands/stop.ts:7-24
System Integration
The /stop command is a key component of the bot's command suite and is integrated into the application's startup and event handling routines.
Command Registration
The command is registered with Discord when the application starts (if GUILD_ID is set) or when the deploy script is run. The stopCommand object is included in an array of commands that are sent to the Discord API.
This diagram shows how commands are collected and registered.
Event Routing
The main application file, app.ts, sets up a listener for the interactionCreate event. A switch statement checks the commandName of the incoming interaction and calls the corresponding handler.
// src/app.ts:20-44
client.on('interactionCreate', async (interaction) => {
if (!interaction.isCommand()) return;
// ... telemetry tracking ...
switch (interaction.commandName) {
// ... other cases
case 'stop':
await stopCommandHandler(interaction);
break;
}
});
Sources: src/app.ts:20, 41-43
Impact on System State
The primary effect of the /stop command is the removal of a user's translation settings. The settingsStorage module is responsible for managing these settings.
- The
/startcommand usessettingsStorage.set()to store a user's target language. - The
/stopcommand usessettingsStorage.delete()to remove that entry. - The
/statuscommand usessettingsStorage.get()to check if an entry exists and inform the user of their current translation status. - The voice processing logic in
joinCommandHandleralso usessettingsStorage.get()to decide whether to translate a user's speech. If no settings are found for a speaking user, their audio is ignored.
Sources: src/commands/start.ts:40, src/commands/stop.ts:16, src/commands/status.ts:16, src/commands/join.ts:80-81