A powerful and open source Discord bot, LangBot is aimed at stopping the language barrier we experience in large Discord servers, members may want to speak other languages, however they are not allowed to, as it's hard for moderators to... moderate. So I came up with a Discord bot, that instantly replies to a message with a translation and language of origin. Want to translate something secretly? Well you can with the /translate <prompt> (language)
command, where you enter a prompt in any language, and the bot will translate it for you into your desired language (en by default), where only you can see it!
Adding LangBot to your guild is very straightforward, as the bot is very plug-and-play, with all configs preset with default values.
- Invite the bot to your server.
- The bot needs very few permissions, "Send Messages" and "View Channels."
- If you would like to customize your config, look at the Admin Commands section.
- And you're done!
- Simple - The source code is well commented, aimed at making it easier to understand.
- Fast - The bot works asynchronously, allowing multiple operations at the same time.
- Configurable - Admins can configure features in their guild with the
/config
command. - Reliable - The bot uses Google Translates API for translation, meaning it is as reliable as Google Translate.
LangBot interacts with the Discord API using discord.py, allowing for blazing fast communication, and simplicity within the source code. Translation is done with custom functions, allowing for reliable and stable translation. The customizable config is held on a MongoDB server, meaning it is secure. You are able to customize the translation message, by default being: {flag} โ {translated}
which looks like this: ๐ฉ๐ช โ Hello World
(flag is shown in Discord), with lots of placeholders you are able to customize this message to your liking. The automatic translation feature looks at the channel-based or guild-based config for the target language
and ignored language(s)
, if any message is not meant to be ignored, it will be translated into the target language
, meaning you can customize what languages the bot should ignore, and what language to translate to. The /translate
command uses the exact same system, however only processing when the command is called, rather than every message it sees. All inputs that may require a language, such as the (language)
parameter in /translate
can either be the language code (such as en
) or the language name (such as English
).
Description: This command allows users to secretly translate messages into any language.
Usage:
/translate <prompt> (language)
How It Works:
- The bot checks if the user specified a language, if they did, ensure it is valid, if the user doesn't specify a language, it will default to the guild's config target language.
- Then the bot determines what language the
<prompt>
is in. - It then translates the message using the
(language)
parameter.
Example:
User: /translate ja jestem polski
Bot (Private Reply): [Polish โ English]
I am Polish
Description: Fetches a list of all supported languages from a custom dictionary, and places them in a paginated embed.
Usage:
/supported
How It Works:
- The bot gets a Python dictionary of all supported languages from a custom dictionary.
- Then the bot paginates these languages (as there are over 300) into 30 languages per page.
- It then sends an embed with buttons to travel through the pages.
Example:
/supported
Description:
Allows the configuration of the bot in the guild, such as translation reply formats, target and ignored languages and other settings, the /config
command is just a parent command, housing a list of subcommands
, which may or may not have an optional value
parameter (?
as the parameter may not exist for some subcommands), leaving the value parameter blank will display the current setting and information about that configuration option. NOTE: the reset subcommand will also wipe all channel-based configs! Here's a list of subcommands:
/config view
- View all current configurations, with a description for each one./config reset
- Reset the guild's configurations to their default values./config translation-reply-message (value)
- Change the message that the bot replies with on translation, thevalue
parameter accepts placeholders, here's a list of all placeholders:{flag}
- The flag of the untranslated languages country.{translated}
- The translated message.{original}
- The original untranslated message.{author_id}
- The ID of the author of the message.{author_display_name}
- The display name of the author of the message.{author_username}
- The username of the author of the message.{author_mention}
- Mention the author of the message.{author_avatar}
- The avatar of the author of the message.{guild_id}
- The ID of the guild of the message.{guild_name}
- The name of the guild of the message.{channel_id}
- The ID of the channel of the message.{channel_name}
- The name of the channel of the message.{message_id}
- The ID of the original untranslated message.{message_url}
- The URL to the original untranslated message.{lang_code}
- The language code of the untranslated message (for example:en
).{lang_name}
- The language name of the untranslated message (for example:English
).
/config target-language (value)
- Change the language that the bot will translate messages into when replying, must be a valid language (check/supported
)./config ignore-languages (value)
- A list of languages to ignore, separated by commas (for example:en, de, fr
). Only enter "nothing" to disable this./config ignore-bots (value)
- A true or false statement, iffalse
the bot will translate messages from other bots (if their languages are not in the ignored list)./config ignored-terms (value)
- A list of words that are not allowed to be translated, if the translated message contains one of these, it will not be translated. Only enter "nothing" to disable this./config reply (value)
- A true of false statement, iffalse
the bot will send the message in the channel, otherwise it will reply to the untranslated message./config ignored-roles (value)
- A list of @mentions, if a user has any of these mentions, they will be blocked by automatic translation. Only enter "nothing" to disable this./config blacklisted-roles (value)
- A list of @mentions, if a user has any of these mentions, they will be blocked by automatic translation. Only enter "nothing" to disable this./config auto-translate (value)
- If false the bot will ignore any message, regardless of the language its spoken in.
Usage:
/config view
/config reset
/config translation-reply-message {flag} >>> {translated}
/config target-language en
/config ignore-languages en, fr, de
/config ignore-bots true
/config ignored-terms hello, world
/config reply false
/config ignored-roles @owner @coolguy
=======
/config blacklisted-roles @owner @coolguy
/config auto-translate true
Default Values:
- Translation reply message:
{flag} โ {translated}
- Target Language:
en
- Ignore Languages:
en
- Ignore Bots:
true
- Ignored Terms:
"lmaoo", "wdym", "ik", "ik lol"
- Reply:
true
- Blacklisted Roles:
none
- Auto Translate:
true
Description: This is an extension to the original guild-based config, it allows for channels to have custom configurations, alongside the guild-based one, meaning that you can have your main guild-based config as a default, and then set a few channels to contain other configuration options, outside the default config, allowing you to have other language channels, which can translate into that channels language. All (other than channel) parameters in set are optional, see default values. Here's a list of subcommands:
/channel-config view
- View all channel configurations as a paginated list, alongside information regarding channel configs./channel-config set {channel} (values)
- Set a channel config for a specific channel, the parameters will match the/config
parameters./channel-config remove {channel}
- Remove a channel configuration from a specific channel.
Usage:
/channel-config view
/channel-config set #general translate_reply_message = "{translated} = {flag}" ignore_languages = en,fr
/channel-config remove #general
Default Values:
On the set subcommand, all parameters, besides channel
are optional, and if left blank, it will set the value to the value in the guild-based config.
This bot is open-source, meaning you are able to clone this repository and play around with it yourself, however, under the laws of the Prosperity Public License agreements, you may NOT distribute, sublicense or publically share any part of this software without my written approval.
- Clone the repository
git clone https://github.com/Mazurex/Langbot.git cd LangBot
- Install dependencies
pip install -r requirements.txt
- Configure environment variables
- Rename
.env.example
to.env
and fill in your bot token & MongoDB URI - Ensure you have a MongoDB database set up. You can use MongoDB Atlas (cloud-based) or run MongoDB locally.
- Rename
- Run the bot
python -m bot.main
Love the bot? Consider supporting development with a donation!
Want to contribute? Follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature-branch
) - Commit changes (
git commit -m "Added a new feature"
) - Push to your branch (
git push origin feature-branch
) - Open a Pull Request
This project is licensed under the Prosperity Public Licenseโsee the LICENSE file for details.
- Discord Server: Invite Link
- GitHub Issues: Report Bugs
- Email: [email protected]
- Mazurex - Developer, Tester
- Azy Supreme - Tester
- codingcat - Tester
- Random_Chad - Tester