如何解决Discord Translation Bot AttributeError:“ NoneType”对象没有属性“ group”
所以我正在尝试用python编写一个discord bot,它运行得很好,它可以很好地跨2个不同的通道转换大多数消息,但是在某些消息上我得到了AttributeError:'NoneType'对象没有属性'group'
我的代码是:
@client.event
async def on_message(message):
dutch_channel = 123456789
english_channel = 123456789
translator = googletrans.Translator()
text = message.content
if message.author == client.user:
return
if message.channel.id == dutch_channel:
try:
text_translated = translator.translate(text,dest = 'english')
channel = client.get_channel(english_channel)
await channel.send(f'__**{message.author.name}**__ \r\n {text_translated.text}')
except AttributeError:
print(message.content)
if message.channel.id == english_channel:
try:
text_translated = translator.translate(text,dest = 'dutch')
channel = client.get_channel(dutch_channel)
await channel.send(f'__**{message.author.name}**__ \r\n {text_translated.text}')
except AttributeError:
print(message.content)
await client.process_commands(message)
我认为这是因为特殊字符而引起的,至少我知道特殊字符总是会引起问题。
其他信息:
完整的堆栈跟踪:
message
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Users\Wessel\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py",line 333,in _run_event
await coro(*args,**kwargs)
File "c:\Users\Wessel\Desktop\PythonBot\bot.py",line 88,in on_message
output = f' \r\n {text_translated.text}'
UnboundLocalError: local variable 'text_translated' referenced before assignment
Discord.py版本1.5.1 GoogleTrans版本3.0.0
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。