Skip to content Skip to sidebar Skip to footer

Discord.py Know If User Exists In Server

Sorry to bother everyone, I know this is duplicated but I don't have the rank to comment so I have to ask again, I've seen some other posts about this and all of them say you manua

Solution 1:

In on_message(message), you can get the guild via message.guild:

@client.event #Maybe you use client or maybe bot, then you would have to change this to whatever of them you haveasyncdefon_message(message):
    guild = message.guild
    if guild.get_member(ID_OF_MEMBER) isnotNone: # find ID by right clicking on a user and choosing "copy id" at the bottom# the member is in the server, do something #else:
        # the member is not in the server, do something #

To be able to use guild.get_member, you have to enable member intents in your developer dashboard in your application under bot: Member intents and at the top of your code, where you define client, change client = ... to:

intents = discord.Intents.default()
intents.members = True
client = commands.Bot(... whatever you have here, intents=intents) #this line can be different for you!

References:

Post a Comment for "Discord.py Know If User Exists In Server"