在我玩代码时,我想知道是否可以返回Invite.unique,但出现此错误:
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Users\Mike\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\client.py", line 312, in _run_event
await coro(*args, **kwargs)
File "C:\Users\Mike\PycharmProjects\projectA\mygame.py", line 245, in on_message
if invite.unique:
AttributeError: 'Invite' object has no attribute 'unique'
我正在使用PyCharm 2019.3.5,Python 3.8和on_message()
。这是我的代码:
try:
invite = await message.channel.create_invite(unique=False)
except Exception as e:
invite = await message.channel.create_invite(unique=True)
print(e)
embed = discord.Embed(
title='Successful Invite',
description=f'Invite Link: {invite}',
colour=discord.Colour.blue()
)
if invite.max_age == 0:
embed.add_field(name='# of sec', value='Infinity')
else:
embed.add_field(name='# of sec', value=invite.max_age)
if invite.max_uses == 0:
embed.add_field(name='# of uses', value='Infinity')
else:
embed.add_field(name='# of uses', value=invite.max_uses)
if invite.unique:
embed.add_field(name='Unique', value='True')
else:
embed.add_field(name='Unqiue', value='False')
await message.channel.send(embed=embed)
我应该做什么?
答案 0 :(得分:0)
unique
不是存储的属性,因此是错误。根据文档,unique
只是确定它是创建新的URL还是使用先前的URL。如果这对您确实很重要,则需要在代码中进行处理。 – DaveStSomeWhere