I’ve set up a Discord bot that needs to get users’ email addresses for a specific task. I changed the OAuth scope to include email, but I’m still not seeing the email property in the user object.
Here’s what I’ve done:
Updated my authorization URL to include the email scope
Set up a test function to log the user object when a message is received
Getting user emails through a Discord bot isn’t straightforward. You can’t just access it from message events. Instead, you need to use OAuth2 with the ‘email’ scope. Set up an authorization flow where users grant permission. Once authorized, use the access token to fetch user data from the /users/@me endpoint. This should include the email if available. Keep in mind that not all users have verified emails, so you might get null values sometimes. Also, make sure your bot’s privacy policy clearly states how you’ll use email addresses to comply with data protection regulations.
hey there! to get user emails, u gotta use OAuth2 with the ‘email’ scope. make users go thru the auth process with that scope, then use the access token to hit the /users/@me endpoint. remember tho, not everyone has a verified email, so it might be null sometimes. good luck!
I recently tackled a similar issue and learned that you can’t simply extract emails from events such as message receives. Instead, you must integrate OAuth2 properly with the email scope. Begin by building an authorization URL that includes both the identify and email scopes and have users visit that URL. After authorization, exchange the provided code for an access token and then fetch the user’s data from the /users/@me endpoint. Note that not every user has a verified email, so you might encounter null values. It is also important to address data protection properly.