简体   繁体   中英

AttributeError: 'Invite' object has no attribute 'unique' | discord.py

When I was playing with code, I wondered if I could return Invite.unique, but I get this error:

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'

I am using PyCharm 2019.3.5, Python 3.8 and on_message() . Here is my code:

            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)

Any idea of what I should do?

unique is not a stored attribute, hence the error. According to the docs, unique just determines if it creates a new url or uses a previous one. If it really matters to you, you'll need to handle yourself in the code. – DaveStSomeWhere

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM