【发布时间】:2021-05-10 03:14:41
【问题描述】:
所以我有一个用户对象,但我想在公会中访问他们的昵称,我也有。 有没有办法做到这一点?还是我完全不了解。
谢谢。
我试过了,但没用:
intents = discord.Intents.default()
intents.members = True
@client.command(pass_context = True)
async def test(ctx,id):
name = ctx.author.guild.get_member(id).nick
return name
错误是:AttributeError: 'NoneType' object has no attribute 'nick'
【问题讨论】:
-
你需要得到公会实例,然后你可以使用
Guild.get_member方法 -
我试过了,但没用,如上所示。
-
您还需要启用
intents.members在Guild.get_member方法中您应该传递一个ID 而不是整个discord.User实例 -
虽然我在 Developer Portal 中启用了 Intent,但仍然出现同样的错误。
-
您还需要在代码中启用它们。
标签: python discord discord.py