'NoneType' 对象在尝试查找用户是否在特定服务器 discord.py 中时没有属性 'get_member' 错误

时间:2021-02-23 22:23:09

标签: python discord discord.py

@client.event
async def on_message(message):
    if not message.guild:
        userid = message.author.id
        guild = client.get_guild(123456789) #example id
        if guild.get_user(userid) is not None:
            pass
        else:
            await message.channel.send("You aren't in example server")

这是为了检查消息是否在 DM 中,如果是,则检查它们是否在指定的服务器中。当我运行这个时,我得到“NoneType”对象没有属性“get_user””

1 个答案:

答案 0 :(得分:0)

您需要使用 guild.get_member(userid)

@client.event
async def on_message(message):
    if not message.guild:
        userid = message.author.id
        guild = client.get_guild(123456789) #example id
        if guild.get_member(userid) is not None:
            pass
        else:
            await message.channel.send("You aren't in example server")