I'm trying to use Python to implement a Discord bot, mainly using the Google Translate API. The bot.py source file looks like this:
from dotenv import load_dotenv
from googletrans import Translator
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
GUILD = os.getenv('DISCORD_GUILD')
bot = commands.Bot(command_prefix=('!', '$', '#', '.'))
@bot.command()
async def translate(ctx, firstlang, secondlang, word):
translator = Translator()
result = translator.translate(word, dest=secondlang, src=firstlang)
await ctx.send(f'```The translation of your word/phrase is: {result}```')
bot.run(TOKEN)
However, when I try running
$translate en es door
on my server I get
Ignoring exception in command translate:
Traceback (most recent call last):
File "/home/aurinko/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "bot.py", line 44, in translate
result = translator.translate(word, dest=secondlang, src=firstlang)
File "/home/aurinko/lib/python3.8/site-packages/googletrans/client.py", line 182, in translate
data = self._translate(text, dest, src, kwargs)
File "/home/aurinko/lib/python3.8/site-packages/googletrans/client.py", line 78, in _translate
token = self.token_acquirer.do(text)
File "/home/aurinko/lib/python3.8/site-packages/googletrans/gtoken.py", line 194, in do
self._update()
File "/home/aurinko/lib/python3.8/site-packages/googletrans/gtoken.py", line 62, in _update
code = self.RE_TKK.search(r.text).group(1).replace('var ', '')
AttributeError: 'NoneType' object has no attribute 'group'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/aurinko/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "/home/aurinko/lib/python3.8/site-packages/discord/ext/commands/core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "/home/aurinko/lib/python3.8/site-packages/discord/ext/commands/core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'group'
how would you go about this? Any help is appreciated