Hey andrew,
I’ve actually just built a Discord-integrated system for a community based website, with automatic role syncing and everything. Was a fun project.
We accomplished this just using Bubble’s API Connector. I highly recommend using that as opposed to any Discord plugin out on the market right now. Maybe it’s time I make a Discord plugin…? Hmmm… Lol
If you have any specific questions I can try to help, but I’ll give you the basics for how we setup the connection to user accounts.
When creating the API call, for Authentication, I just used None or self-handled - because I had a Data structure setup where I saved users Discord Code, Discord Token, Refresh Token, Expiration Date, and Discord ID of the user.
To be fully honest, it does get slightly complicated with the setting up. Essentially, when a user logs in, they are prompted to link Discord. They are then sent to Discord’s oAuth login page, located: https://discord.com/api/oauth2/authorize?response_type=code&client_id=934517161634988062&scope=connections%20email%20identify%20guilds%20guilds.join%20messages.read&state=15773059ghq9183habn&redirect_uri=[WEBSITE REDIRECT HERE]&prompt=consent
- The redirect then goes to a page I setup specifically for Discord linking, where I get a confirmation of “Do you want to link your Discord account” and the user clicks yes or no.
If yes, well, you have to create an API call on the API connector to https://discord.com/api/oauth2/token
as a POST request. This will kick back with a JSON body which I store everything it kicks back with (besides Scope, I don’t save that).
Honestly, it can be pretty complicated. But, it all makes sense in the API doc’s.
Now, this is what all I setup to do user-authentication and to be able to do actions on behalf of the user (such as force-join or force-leave a server, which my client wanted to be able to force a user into their Discord upon acceptance into the community).
If you were just wanting to do stuff on behalf of a bot, such as send DMs, you wouldn’t need to do any of what I just said… Instead, you could:
Create the API calls.
I will show you how to setup the 2 API calls required to send a DM.
Yes, there will need to be 2 different calls. This is because the first call you need to make is to get a Channel ID of a DM, which is a call of it’s own, and then use that Channel ID to actually send a message.
In your API connector, in your Discord section, make a new call. I titled mine “Message - Step 1” - and I use it as Action, with a Data-Type of JSON.
It is a POST request, sent to https://discord.com/api/users/@me/channels
For Headers, you need 2.
Key: Content-Type, Value: application/json
Key: Authorization, Value: Bot [BOT TOKEN HERE]
Where I have Bot Token Here, you will need to paste your Bot’s token. If you don’t have one, or don’t know what I mean, read this:
Now, for body type, you are going to use JSON.
Here is the very easy JSON body I used:
{
"recipient_id":<User ID>
}
Here is a screenshot of this API call, incase I was unclear.
Also take note of what I have as Private and not private.
API Call #2, sending the message.
Alright, similar stuff, little different. The call URL is a POST to https://discord.com/api/channels/[Channel ID]/messages
- It is important to leave the [Channel ID] as is. I’m assuming you’ve used the API Connector before, so you know that is a dynamic field that you can edit when you go to make the call in a workflow.
Same headers, Content-Type: application/json
and Authorization: Bot [BOT TOKEN]
both set to Private.
Body type is JSON, and the body is just as easy.
{
"content":"<Message>"
}
Again, here is a picture of this call on my end.
Note: My Message - Step 2 actually used an Embed, so that is why this is not called Message - Step 2
Actually using the calls.
Okay, now, how do we use these together? Easy.
First, you’ll trigger Step 1, with the Discord User ID that you want to DM.
Then, using your Step 2 call, send the Channel ID of “Result’s of step 1’s body id”
Again, my Step 2 is slightly different than the example. Sorry. But, the Channel ID will be the same.
Conclusion
In conclusion, just know some users have their privacy setup to not receive DMs from Bots. I know there is a way to catch that error and tell the front-end user. I haven’t actually done this myself yet. But it is possible. I hope this helps. I kinda rambled a bit, but let me know if you have any specific questions.