![Globe with flags](https://private-user-images.githubusercontent.com/1623983/325217589-96f1b58b-94f4-4df6-a81c-34e4f0342dc0.jpg?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQxMTIxMTcsIm5iZiI6MTcyNDExMTgxNywicGF0aCI6Ii8xNjIzOTgzLzMyNTIxNzU4OS05NmYxYjU4Yi05NGY0LTRkZjYtYTgxYy0zNGU0ZjAzNDJkYzAuanBnP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDgxOSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA4MTlUMjM1NjU3WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9OGJiNjgxZThkYTUyYmRkMjEwMTdkYjM5NjM3M2JhMDUwNDViOGNiYjEzNzIzOWRmODIxMjk0NjA2YjU0NjhjMiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.ol76D8zouGAOZrT5cyBTk2ZJ-WJWKEGSoun7ATNriy8)
A Discord bot that allows translations of messages in a Discord server (guild) using country flags and /translate
command, powered by .NET
and Discord.Net.
It supports the following translation providers, all of which are disabled by default, that run in the following order:
- Azure Translator (has a free tier)
- LibreTranslate (free and open-source)
If any provider fails to provide a translation, the bot will use the next provider if any as a fallback. At least one provider is required or else the app will exit with an error.
Which providers are enabled can be configured per the instructions below.
- Go to the Discord Developer Portal and create a new application with the name you want the bot to have.
- Go to the "Bot" tab in the sidebar and create a bot. Take note of the bot token to use for development or production. Check the setting for whether you want it to be a Public Bot or not.
- Enable "Message Content Intent" under Privileged Gateway Intents.
- Go to the "OAuth2" -> "URL Generator" tab in the sidebar. Check the following scopes:
bot
and permissions:Send Messages
,Manage Messages
, andRead Message History
. - Copy the Generated URL and open it in your browser to add the bot to your Discord server.
- Follow the steps to create and run a LibreTranslate Docker container.
- Optionally, you can mount the volumes
/root/.local/share/LibreTranslate
and/root/.local/share/argos-translate
to persist the language models. This is good for production.
- Configure the user secrets file with the required environment variables. Example below:
{
"Discord": {
"BotToken": ""
},
"TranslationProviders": {
"AzureTranslator": {
"Enabled": true,
"ApiUrl": "https://api.cognitive.microsofttranslator.com",
"SecretKey": "",
"Region": ""
},
"LibreTranslate": {
"Enabled": true,
"ApiUrl": "http://localhost:5000"
}
}
}
- Make sure that you've created a Discord bot and have configured at least one translation provider using the steps above.
- Build a Docker image with
docker build -t discordtranslationbot .
in the directory that contains theDockerfile
. - Create and run a container with
docker run discordtranslationbot
and the following environment variables configured. Make sure that you've created a Discord bot and have configured at least one translation provider using the steps above. Example below:
Discord__BotToken=
TranslationProviders__AzureTranslator__Enabled=true
TranslationProviders__AzureTranslator__ApiUrl=https://api.cognitive.microsofttranslator.com
TranslationProviders__AzureTranslator__SecretKey=
TranslationProviders__AzureTranslator__Region=
TranslationProviders__LibreTranslate__Enabled=true
TranslationProviders__LibreTranslate__ApiUrl=http://localhost:5000
All translation providers are disabled by default. Set the TranslationProviders__ProviderName__Enabled
config setting
to true
for those you which to
enable. When a provider is enabled, you must provide the related config settings for the provider or the app will exit
with an error.
See LICENSE file in this repo.
This app has been developed by Austin S.