![](/img/trans.png)
[英]AttributeError: 'NoneType' object has no attribute 'name' discord.py
[英]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
我不知道為什么會出現這個錯誤,因為它沒有任何意義。 我試圖更改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)
參考文檔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
變量中
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.