python - discord.py 中的翻译命令无法正常工作
问题描述
所以我正在尝试制作一个翻译命令,在该命令中我可以允许其他用户单独将单词(例如 Hello World)翻译成其他语言(例如德语)
但是,事情并没有像他们应该的那样工作......它返回这个错误,例如:
Ignoring exception in command translate:
Traceback (most recent call last):
File "C:\Python39\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "C:\Python39\lib\site-packages\discord\ext\commands\core.py", line 855, in invoke
await self.prepare(ctx)
File "C:\Python39\lib\site-packages\discord\ext\commands\core.py", line 789, in prepare
await self._parse_arguments(ctx)
File "C:\Python39\lib\site-packages\discord\ext\commands\core.py", line 706, in _parse_arguments
kwargs[name] = await self.transform(ctx, param)
File "C:\Python39\lib\site-packages\discord\ext\commands\core.py", line 542, in transform
raise MissingRequiredArgument(param)
discord.ext.commands.errors.MissingRequiredArgument: text is a required argument that is missing.
Ignoring exception in command translate:
Traceback (most recent call last):
File "C:\Python39\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "no", line 253, in translate
translated = translator.translate(text, src=fro, dest=to)
File "C:\Python39\lib\site-packages\googletrans\client.py", line 182, in translate
data = self._translate(text, dest, src, kwargs)
File "C:\Python39\lib\site-packages\googletrans\client.py", line 78, in _translate
token = self.token_acquirer.do(text)
File "C:\Python39\lib\site-packages\googletrans\gtoken.py", line 194, in do
self._update()
File "C:\Python39\lib\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 "C:\Python39\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "C:\Python39\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Python39\lib\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'
已经使用的代码是这个:
import googletrans
from googletrans import Translator
@client.command(aliases = ['trans'])
async def translate(ctx, fro, to, *, text):
translator = Translator(service_urls = ['translate.googleapis.com'])
translated = translator.translate(text, src=fro, dest=to)
embed = discord.Embed(title="Translator", color=0xff2200)
embed.set_footer(text=f"Requested by {ctx.author.name}#{ctx.author.discriminator}", icon_url=f"{ctx.author.avatar_url}")
embed.add_field(name="From language", value=fro.capitalize(), inline=False)
embed.add_field(name="What is being Translated", value=text, inline=False)
embed.add_field(name="To Language", value=to.capitalize(), inline=False)
embed.add_field(name="Translated Text", value=translated.text, inline=False)
await ctx.send(embed=embed)
所需的东西(在本例中为 googletrans 4.0.0-rc1)已安装并导入......但它仍然拒绝工作......
解决方案
推荐阅读
- html - Angular 6通过服务显示来自rest api的数据
- java - 卡片容器在网格布局中未正确显示
- html - 白线出现在特定浏览器宽度的渐变填充 div 的末尾
- docker - Kafka集群模式端口配置
- python - 在 wx.ListBox 开头添加字符串
- html - 如何从我的网站中删除空格?
- zend-framework - ZF3:EventManager 中的 SharedEventManager 注入
- excel - 状态栏指标的 VBA 对象
- javascript - 拖动多边形时如何更新谷歌地图的纬度和经度
- java - 为什么我不能将 Tomcat 9 添加到 Netbeans 8