首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AttributeError:'Invite‘对象没有'unique’属性| discord.py

AttributeError:'Invite‘对象没有'unique’属性| discord.py
EN

Stack Overflow用户
提问于 2020-05-16 09:28:29
回答 1查看 54关注 0票数 0

当我使用代码时,我想知道是否可以返回Invite.unique,但我得到了这个错误:

代码语言:javascript
复制
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,Python3.8和on_message()。下面是我的代码:

代码语言:javascript
复制
            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)

你知道我该怎么做吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-19 06:12:29

unique不是存储属性,因此出现错误。根据文档,unique只是确定它是创建新的url还是使用以前的url。如果它真的对您很重要,那么您需要在代码中处理自己。- DaveStSomeWhere

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61830758

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档