我正在尝试使用python实现一个discord机器人,主要使用GoogleTranslateAPI。bot.py源文件如下所示:
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)
然而,当我试着跑步的时候
$translate en es door
在我的服务器上,我得到
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'
你会怎么做?谢谢你的帮助
暂无答案!
目前还没有任何答案,快来回答吧!