AttributeError:“邀请”对象没有属性“唯一”不和谐

时间:2020-05-16 01:28:28

标签: python discord discord.py discord.py-rewrite

在我玩代码时,我想知道是否可以返回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)

我应该做什么?

1 个答案:

答案 0 :(得分:0)

unique不是存储的属性,因此是错误。根据文档,unique只是确定它是创建新的URL还是使用先前的URL。如果这对您确实很重要,则需要在代码中进行处理。 – DaveStSomeWhere