简体   繁体   English

discord.py: AttributeError: 'NoneType' object 没有属性 'name'

[英]discord.py: AttributeError: 'NoneType' object has no attribute 'name'

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

I don't know why this error shows, because it doesn't make any sense.我不知道为什么会出现这个错误,因为它没有任何意义。 I've tried to change the disnake.utils.get function, but it doesn't work.我试图更改disnake.utils.get function,但它不起作用。

# 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)

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

It clearly states: If nothing matching the passed attributes is found, None is returned.它明确指出: If nothing matching the passed attributes is found, None is returned.

When there are no results of getting a value in an iterable sequence disnake.utils.get put the value None in the user variable当在可迭代序列disnake.utils.get中获取值没有结果时,将值 None 放入user变量中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AttributeError: 'NoneType' object 没有属性 'name' discord.py - AttributeError: 'NoneType' object has no attribute 'name' discord.py AttributeError: 'Nonetype' 对象在 discord.py 中没有属性 'roles' - AttributeError: 'Nonetype' object has no attribute 'roles' in discord.py AttributeError: 'NoneType' 对象没有属性 'channel' discord.py - AttributeError: 'NoneType' object has no attribute 'channel' discord.py AttributeError: 'NoneType' object 没有属性 'send' discord.py - AttributeError: 'NoneType' object has no attribute 'send' discord.py discord.py (rewrite) AttributeError: 'NoneType' object has no attribute 'edit' - discord.py (rewrite) AttributeError: 'NoneType' object has no attribute 'edit' Discord.py - AttributeError: 'NoneType' object 没有属性 'send' - Discord.py - AttributeError: 'NoneType' object has no attribute 'send' Discord.py AttributeError:“NoneType”对象没有“发送”属性 - Discord.py AttributeError: 'NoneType' object has no attribute 'send' AttributeError: 'NoneType' object 没有属性 'count' - discord.py - AttributeError: 'NoneType' object has no attribute 'count' - discord.py AttributeError: 'NoneType' object 没有属性 'play' discord.py - AttributeError: 'NoneType' object has no attribute 'play' discord.py AttributeError: 'NoneType' object 没有属性 'edit' discord.py - AttributeError: 'NoneType' object has no attribute 'edit' discord.py
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM