因此,我可以使用以下代码检查用户在服务器中的角色:
#Check Admin:
playerRoles = []
for x in message.author.roles:
playerRoles.append(str(x))
if "Admin" in playerRoles:
但是我希望bot能够检测到它们在与发出命令的服务器不同的服务器中的角色。我希望命令能够通过将其管理到bot来发出,因此显然我不能使用message.author.roles,因为用户在DMs中没有角色,所以他在服务器中有角色
以下是我尝试过的:
#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中的“for x”行返回错误:
AttributeError:“非类型”对象没有属性“角色”
我猜它获得的“目标用户”不是那种有角色的人。感觉坏蛋。如何从DMs中发出的命令中获取用户在服务器中的角色
谢谢你的帮助
AttributeError: 'NoneType' object has no attribute 'roles'
表示targetUser
是None
所以你的
discord.utils.get(pepeServer.members, id=userID)
没有返回任何东西检查服务器和用户id
相关问题 更多 >
编程相关推荐