Skip to content

Commit

Permalink
Update main.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ChocoMeow committed Feb 2, 2023
1 parent 0d1ddb3 commit 142f9aa
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@
)
from discord.ext import commands
from dotenv import load_dotenv
from googletrans import Translator
from datetime import datetime
from voicelink import VoicelinkException

translator = Translator()

load_dotenv()

class Translator(discord.app_commands.Translator):
Expand All @@ -29,12 +26,7 @@ async def unload(self):

async def translate(self, string: discord.app_commands.locale_str, locale: discord.Locale, context: discord.app_commands.TranslationContext):
if str(locale) in local_langs:
text = local_langs[str(locale)].get(string.message, None)
if not text:
result = translator.translate(string.message, str(locale).lower())
print(result.origin, ' -> ', result.text)
return result.text
return text
return local_langs[str(locale)].get(string.message, None)
return None

class Vocard(commands.Bot):
Expand All @@ -53,8 +45,8 @@ async def setup_hook(self):
except Exception as e:
print(traceback.format_exc())

# await bot.tree.set_translator(Translator())
# await bot.tree.sync()
await bot.tree.set_translator(Translator())
await bot.tree.sync()

async def on_ready(self):
print("------------------")
Expand Down

0 comments on commit 142f9aa

Please sign in to comment.