[英]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.