This example creates an application command with a name and description based on the locale of the user interacting with the bot. Once the command is created, it listens for an interaction (while connected to the Discord Gateway), then responds to the interaction accordingly. The bot waits until the program receives a signal to terminate, then disconnects from the Discord Gateway and deletes the created command. For more information about localization, read the Discord API Documentation.
Use this example to create localized commands for users.
You must create a Discord Application in the Discord Developer Portal to receive your Bot Token.
Assign an environment variable in the command line you will be running the program from.
set TOKEN=value
set APPID=value
export TOKEN=value
export APPID=value
NEVER SHOW YOUR TOKEN TO THE PUBLIC.
NOTE: Get the Application ID by enabling Developer Mode from the settings of your account, then right clicking your bot.
Use go build
to build the executable binary. Use localization
to run it from the command line.
> localization
Program is started.
Creating an application command...
Adding an event handler.
Connecting to the Discord Gateway...
Successfully connected to the Discord Gateway. Waiting for an interaction...
Upon receiving an interaction from the user, the bot will respond with a message in the language of the user's locale. When the user's locale is not supported, the bot will state that The current locale is not supported by this command.
Use ctrl + C
or cmd + C
in the terminal.
Exiting program due to signal...
Disconnected from the Discord Gateway.
Deleting the application command...
Program executed successfully.