Send a dm to user after bot/app has been added/authorized? (user install)
I would like the process of adding my bot to go something like this:
1. Lets say I send the bot authorization link to one of my friends, to showcase it (https://discord.com/oauth2/authorize?client_id=xxxxxx)
2. They click on the link and authorize it, and upon getting back to Discord they will receive a DM like:
3. And then they can execute those commands as they wish.
How could I achieve this? Does there exist a call that happens when a user authorizes the bot? My initial thought was that this does not exist, but maybe I could use oauth redirects, however I ran into problems there too.
This link redirects correctly, with a code that looks like this "Mz9AVQsPphK3uqdTZcxUL2kJaEDH46", I am not quite sure what to do with it, but either way, when response_type is "code", the app actually doesn't get authorized.
However if the response type is "token", redirection works, and the app does actually get authorized, but from my understanding it is limited to 7 days. In my case this might be alright though.
So now after redirecting, I can get the access_token, and in theory, if I also add the
identify
scope, I should be able to get user information with the Discord API. However this returns message 401. Having the identify
scope alone works fine, however together with applications.commands
. Doesn't work.28 Replies
- What's your exact discord.js
npm list discord.js
and node node -v
version?
- Not a discord.js issue? Check out #other-js-ts.
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button!There is no way to tell when someone installs your app (as of yet)
But is redirects supposed to not work like that? Like applications.commands+identify does not work, and response_type=code doesnt authorize the app properly.
application.commands
just allows you to add commands to guilds
It has nothing to do it, only way i can think of telling is when someone uses your app, you can check the "authorizing_integration_owners" field of the interaction (asuming you are not using djs and have plain api data)
https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-authorizing-integration-owners-objectBy adding applications.commands to the scope it adds 2 items to the list of what the app will be allowed to do "Send you direct messages (without having to share servers)" and "Create commands".
The reason I want to add both applications.commands and identify to the scope, is because when you authorize an app as user install here on discord, it does not appear in the direct messages tab. You have to first interact with it. I would like the bot to interact with the user when it authorizes the app, giving the user an easier time, instead of making the user try to find the bot by going to discord.com/users/<bots id>
It can only do that for a user install
But no, its not unprompted DMs
Its the ability to respond to slash commands in your DMs without sharing a server
As far as I'm aware anyway
Their query is to tell when someone installs their app as an user app (if i am understanding it correctly), which discord doesn't provide a way for (yet), unless the user (who installed the app) interacts with it
Yes, that is what I wish to achieve.
Yes, thats what I'm also saying
And as far as I know, you can only tell when someone uses your bot's command as an user app, there's not gayeway event for when someone installs your bot (or similar method) as of yet
If the bot has the user id, it has the ability to send the user DMs without the user first sending something. The only thing I really need is the users ID upon adding it, but I suppose that is not possible yet. Sad
I'm not sure that's correct
Have you tested it?
Yeah that's not correct (needs to share servers to send messages)
Because if so, the user id from the identify is all you'd need
And I dont understand what the issue is
I have tested it, and it does work. If the bot has the scope set to
applications.commands
, it will be given the permissions to "Create commands" and "Send you direct messages (without sharing servers)". And if the user authorizes this, the bot, if it has the users ID, will be able to send the user DMs, without the user sending anything first.
Exactly, but the problem is that, combining applications.commands with identity does not work. The token does not work, and if response_type is set to code, it does not get authorized. Setting scope to just identity does make the token work, but I need applications.commands scope for the bot to be able to DM the user.