Oauth2 bot reply

Im stuck if somebody can help: I got the info from the Oauth2, but now im lost as to how to send back a dm to the user
fetch('https://discordapp.com/api/v6/users/@me', {
method: 'GET',
headers: { 'Authorization': `Bearer ${json.access_token}` }
}).then(response => response.json()).then(resp => {MakeappThread(resp.id)})
fetch('https://discordapp.com/api/v6/users/@me', {
method: 'GET',
headers: { 'Authorization': `Bearer ${json.access_token}` }
}).then(response => response.json()).then(resp => {MakeappThread(resp.id)})
the above is fine, im getting the info. this the function that supposed to put the bot instance on
function MakeappThread(UID, servers){

client.on('ready', async () => {

const user = client.users.cache.get(UID);
user.send("HELLO")

});
}
function MakeappThread(UID, servers){

client.on('ready', async () => {

const user = client.users.cache.get(UID);
user.send("HELLO")

});
}
the function is firing, the client doesnt go on
7 Replies
monbrey
monbrey2y ago
I mean, OAuth2 and a bot are really completely different things What client? Where is it logged in? What makes it ready?
Mulo
Mulo2y ago
whenever I use client.whatever, Ineed to be inside a
client.on(...
client.on(...
in this file I have many listeners
client.on('ready', async interaction => { .. })
client.on('interactionCreate', async interaction => { .. })
client.on('messageCreate', async (msg) => {.. })
etc..
client.on('ready', async interaction => { .. })
client.on('interactionCreate', async interaction => { .. })
client.on('messageCreate', async (msg) => {.. })
etc..
all the client.user, cache methods have to be used inside those client.on main function listeners in this same file i have the backend express routes that handle the auth2
app.get('/apps/application', async (req, res) => {
...
fetch('https://discordapp.com/api/v6/users/@me', {
method: 'GET',
headers: { 'Authorization': `Bearer ${json.access_token}` }
}).then(response => response.json()).then(resp => console.log(resp.id))
}
app.get('/apps/application', async (req, res) => {
...
fetch('https://discordapp.com/api/v6/users/@me', {
method: 'GET',
headers: { 'Authorization': `Bearer ${json.access_token}` }
}).then(response => response.json()).then(resp => console.log(resp.id))
}
i cannot use client.user or whatever inside an express endpoint, unless inside a .then() i make a new instance of the bot online, but that sounds weird the bot logins at the bottom of this file `client.login(token) I know Oauth2 and bot are 2 different things (that is why i put the backend and the bot in the same file) @yinoguns which scope do you mean
Yinoguns
Yinoguns2y ago
JavaScript scope
Mulo
Mulo2y ago
anywhere in the module?
Yinoguns
Yinoguns2y ago
Basic JS. If the client is in scope, then it is usable. Events are mearly the expected cause of needing to envoke the client in some way.
monbrey
monbrey2y ago
all the client.user, cache methods have to be used inside those client.on main function listeners
This is technically true but that doesn't mean your ready event is going to fire again just because an OAuth2 endpoint called a function Assuming you do have a client in scope, it's probably already fired ready at this point
function MakeappThread(UID, servers){
if(client.isReady()) {
// send message
}
}
function MakeappThread(UID, servers){
if(client.isReady()) {
// send message
}
}
you would just need to check that its ready, then use it
Mulo
Mulo2y ago
holy crap is working i thought i needed to be insice a client scope thanks guys
Want results from more Discord servers?
Add your server
More Posts
Does it run? Like does the v14 work so a bot can use it?Hello i wonder if i can update my bot to v14 so it works and runs normal? Just so i can try or shoulApplication Command Permissions - Bearer Token requiredI wanted to change permission overwrites for my commands, but, as you can see in the screenshot beloEmbed not populating?My command: https://srcb.in/ckid4AXlBk The `console.log(embeds)`: https://srcb.in/0zq3X8Ramm It logBeen a while since I coded with DJS. How do I listen for the (not as new but still newer) replies...I am not sure how to listen to replies like the attached image. This works to run commands and I'd lWeird DJS err... something about cannot use 'in' operator to search for color?This is my command: https://srcb.in/832iYRGVCa I saw that we can now use embed objects here: https:Been a bit since I worked with DJS V13, How do I add multiple buttons again?I have this code: ```javascript const row = new MessageActionRow() .addComponentTypeError Cannot read properties of undefined (reading 'permissions')Hello, i have this piece of code and i get this error. Code: ```js if (message.member.roles.cacheproblem with timeouthey, when I want to check if a user is timeouted, when my bot restarts, my friend is timeouted but tmodal don't showhi there, I was working in a modal command that works with buttons, but for some reason modal don't interaction.replied returns false when the interaction has been deffered and followed upHow can I gauge if an interaction has been replied then?