因此,我可以使用以下代码检查服务器中用户的角色:
#Check Admin:
playerRoles = []
for x in message.author.roles:
playerRoles.append(str(x))
if "Admin" in playerRoles:
但是我希望机器人能够检测到它们在与发出命令的位置不同的服务器中]所具有的角色。我希望该命令能够通过将其DM发送给机器人来发出,因此显然我不能使用message.author.roles,因为用户在DM中没有角色,他在DM中具有角色服务器。
这是我尝试过的:
#Check Roles: playerRoles = [] #target the user manually to get his roles in the event of a DM pepeServer = client.get_guild(guildID) targetUser = discord.utils.get(pepeServer.members, id=userID) for x in targetUser.roles: playerRoles.append(str(x))
这将在“ targetUser.roles中的x中返回错误”
AttributeError:“ NoneType”对象没有属性“角色”
我猜它获得的“ targetUser”不是具有角色的那种。费尔斯巴德曼。如何从DM中发出的命令中获取服务器中用户的角色?
感谢您的帮助
因此,我可以使用以下代码检查服务器中用户的角色:#Check Admin:playerRoles = []中message.author.roles中的x:playerRoles.append(str(x))...
[AttributeError: 'NoneType' object has no attribute 'roles'
表示targetUser
是None
。