@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””
答案 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")