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

discord.py: AttributeError:'NoneType‘对象没有属性'name’
EN

Stack Overflow用户
提问于 2022-05-11 19:18:50
回答 1查看 346关注 0票数 0
代码语言:javascript
复制
Traceback (most recent call last):
  File "C:\Users\Elyes\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\disnake\ui\modal.py", line 229, in _scheduled_task
    await self.callback(interaction)
  File "d:\Workspaces\Python Workspaces\Discord Bots\JustMe Bot\bot.py", line 143, in callback
    print(user.name)
AttributeError: 'NoneType' object has no attribute 'name

我不知道为什么这个错误显示,因为它没有任何意义。我试图更改disnake.utils.get函数,但它不起作用。

代码语言:javascript
复制
# The callback received when the user input is completed.
    async def callback(self, inter: disnake.ModalInteraction):
        # Get the input from the modal
        for key, value in inter.text_values.items():
            # get user by name
            if key == "name":
                # split value by #
                username, discriminator = value.split("#")
                user = disnake.utils.get(inter.channel.guild.members, name=username, discriminator=discriminator)
                print(user.name)
EN

回答 1

Stack Overflow用户

发布于 2022-05-11 20:15:12

参考文档https://docs.disnake.dev/en/latest/api.html?highlight=utils#disnake.utils.get

它清楚地指出:If nothing matching the passed attributes is found, None is returned.

当没有在可迭代序列中获得值的结果时,disnake.utils.get将值None放在user变量中

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

https://stackoverflow.com/questions/72206513

复制
相关文章

相似问题

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