Use Discord's API to send message as user - discord

I want to send a message in a Discord channel but from a user account not a bot. Is this kind of thing possible using Discord's API?

The official documentation should contain enough information to get started: https://discord.com/developers/docs/resources/channel#create-message
Make sure to login with OAuth2 and not as a bot. Also, it is important to get the right scope (permissions) when requesting an OAuth token.

Related

Discord : how to post a message in channels as a user

I'm building an application connecting to Discord. Users can login with Oauth2.0 in the application. My application's goal is to post messages to the channel as a user, not a bot.
I've checked the documentation and the questions already asked, but I couldn't find a way to post as a user.
It would be nice to be APIs, but Execute Webhook and Create Message seem to be for bots.
Is there any API or other way to post to the channel as a user? If anyone knows, please let me know.
Thanks in advance.

Discord API: View guild channels information with Oauth2 guilds scope

I am trying to make a call to /guilds/guild.id/channels endpoint after retrieving a user's guild data that is provided after they successfully authenticate with my app using the Discord's OAuth flow.
My OAuth permissions include email and guilds.
After receiving an access_token I am able to make a call to /users/#me/guilds. However, when I try to iterate over this to access each guild's list of channels using the /guilds/guild.id/channels endpoint I receive a {"message": "401: Unauthorized", "code": 0}. I pass the same access_token in the header of this request.
My question is about the limitations of the Discord API when authenticating with OAuth. The documentation says
Unlike the normal OAuth2 flow, bot accounts have full access to all API routes without using bearer tokens
So can I make an API call to /guilds/guild.id/channels using my access_token?
Or do I have to do this through a bot? And if a bot is required then that means in order to make a call to /guilds/guild.id/channels the bot must first be added to the guild, right?
I believe you falsely assumed that the guilds OAuth2 scope will give you full access to the guilds of the user. This is not the case, the guilds scope only grants the access token permission to view a list of all the user's guilds and basic information of these guilds (guild ID, avatar, name, flags, the user's permission, and whether the user's the owner).
This does not include giving you access to see the guild's channels. The only endpoint guilds scope gives you is /users/#me/guilds which you already know. I believe this is due to user privacy concerns since it unnecessarily lets you to view the channels list from non-related guilds. Most cases when the guilds scope is used, it is to verify if the user's in a certain guild; useful for bot dashboards.
The only way to retrieve a list of channels requires you to have a bot in the guild and use the /guilds/<guild.id>/channels while identifying as your bot.
To see what the OAuth2 scopes actually grants you, it's documented here: https://discord.com/developers/docs/topics/oauth2#shared-resources-oauth2-scopes.

Is it possible to find out what discord bot a token belongs to?

I got multiple discord bots and sometimes it would be useful to find out to what bot a token belongs to via the API or some other way?
I'm using Javachord and I've found there's a getYourself() in DiscordApi that returns a User which represents the current bot.
I'm not sure how that maps to the Discord API itself though
Here's an alternative solution.
Discord has an API endpoint users/#me that returns the current user's user object.
Try this for an example:
curl -H "Authorization: Bot <token>" https://discord.com/api/v9/users/#me
Discord also sends back a user object (part of lots more info) as part of the Identify process when using its websocket gateways, but this probably isn't what you would want.

Last Message Sent by User Messenger Bot

I'm working with Facebook Messenger Bots and I need a way to make an HTTP Request for the last message sent by the user. All I can find is that Messenger Bots send a web hook with the information but, I specifically need to be able to manually check for the last message sent by the user. Any input would be helpful. Thank you.

GMail API - Can I send email using the Service Account?

When I send an email using the GMail API, I get an Access Token for the user to whom the message is to be sent and then when sending the message, I put some value in the From Field.
But no matter what I put in the from field, the message in the email shows as From "Me" and is in the Sent mails as well as Inbox.
Is there a way, I could use the Service Account to send the email, so that it does not show up as From "Me" and is also not in the Sent Mails.
You cannot use a service account to impersonate a free gmail account. I spent a lot of time confirming this after reading a reply that was here before. Maybe it worked at some point, but it doesn't anymore.
There is no way to share / grant another user permission to access
your standard gmail account. So there is no way for you go delegate
the permissions for bob#mycompany.com to access bob#gmail.com.
and
you can impersonate G-Suite accounts but not Gmail accounts
These quotes are from Google's official C# Auth repo:
https://github.com/googleapis/google-api-dotnet-client/issues/1561
No. The Gmail API is for Gmail users and service accounts are just for doing auth to a real Gmail account, they don't have their own Gmail account, etc.
If you want to send the email from some service, you need some bulk-sending email service like at: https://cloud.google.com/compute/docs/tutorials/sending-mail/ or something you run yourself or from some other provider.
No, what you are looking for is a bulk email sending service. Checkout sendgrid , Amazon AWS SES, mandrill or if you want to stick with Google, this. You could of course run your own postfix server (although I'm assuming you were using gmail api for deliverability in the first place.

Resources