AttributeError: 'Invite' object has no attribute 'unique' | discord.py
AttributeError: 'Invite' object has no attribute 'unique' | discord.py
我在玩代码的时候,我想知道我能不能return 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)
知道我应该做什么吗?
unique
不是存储的属性,因此出现错误。根据文档,unique
只是确定它是创建一个新的 url 还是使用以前的一个。如果它对你来说真的很重要,你需要在代码中处理自己。 – DaveStSomeWhere
我在玩代码的时候,我想知道我能不能return 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)
知道我应该做什么吗?
unique
不是存储的属性,因此出现错误。根据文档,unique
只是确定它是创建一个新的 url 还是使用以前的一个。如果它对你来说真的很重要,你需要在代码中处理自己。 – DaveStSomeWhere