Ahsanfr.
DIAdiscord.js - Imagine an app
•Created by Ahsanfr. on 9/8/2024 in #djs-questions
discord dashboard and discord js combo
What i normally do is, i got a protect middleware that runs on each request.
What does the middleware do?
- it checks if JWT is present in cookie
- if jwt is valid
- gets user id from jwt then make request to database to get document with access token
- then make request to discord api /@me endpoint to validate the access token is still valid or not.
So this happens on every endpoint, now, lets say someone goes to settings of a specific server, i will do following
- protect middleware
- make request to api to check if he has certain roles
- make request to api to show all roles, another request to show all channels
- some database requests to get some data
That's a lot of api calls right? Making the web slow. I thought of using discord js for its cache system (would no need to call dapi for checking roles,fetching roles and channels)
But that means running the server as well as bot in same process. What do you guys do?
50 replies
DIAdiscord.js - Imagine an app
•Created by Ahsanfr. on 7/9/2024 in #djs-questions
presence update
Wondering how to differentiate when a person starts a new activtity, such as listening to spotify and that the activity should not be exisiting in old presence. For exaple, user is playing a game + spotify, if spotify updates , the game remains same, it should not show game.
here's what i got so far, seems to work. The
.equals
how does it work? it seems like if i am running vs code since few hours (timestamp property of activity showing start as few hours ago) but edit a new file (createdTimestamp updates), it says true. Is there anyway for me to modify it so it only show when the presence actually starts (running vs code)2 replies
DIAdiscord.js - Imagine an app
•Created by Ahsanfr. on 6/23/2024 in #djs-questions
reaction leaderboard
making a leaderboard for reactions, i wanna store in a json file the points , each point correspond to the emoji. Now i see, there are guild emojis and standard emojis. How do i differnetiate b/w them and store in json and when soeone reacts i can get from json and see this emoji is that one. Standard emojis dont have IDS but names and they are unicode i think? so just store them ?
8 replies
DIAdiscord.js - Imagine an app
•Created by Ahsanfr. on 4/16/2024 in #djs-questions
what would be the best way to generate an invoice like this?
3 replies
DIAdiscord.js - Imagine an app
•Created by Ahsanfr. on 4/10/2024 in #djs-voice
wait for bot to play audio
First time working with it,
I have a cron job running eery 5 minutes. In the callback, the bot fetches an array and loops over it. Each array has a mp3 and a channel id. Now i want to run each mp3 in its own channel.
Scenario:Bot runs the join function, a connection is created. It then listens to ready event and create a player to run audio on the connection.
Issue: when bot loops on first element, it instead of waiting for connection to be established (ready) and running the audio, just attaches the listener, then goes to next item. For next item, it again runs the join function which overrieds the previous connection according to docs.
So how would i make bot wait for connection to be ready, wait for audio to be played, since i cant even await the connection.subscribe ):
Code:
6 replies
DIAdiscord.js - Imagine an app
•Created by Ahsanfr. on 4/10/2024 in #djs-questions
Discordjs/voice
First time working with it,
I have a cron job running eery 5 minutes. In the callback, the bot fetches an array and loops over it. Each array has a mp3 and a channel id. Now i want to run each mp3 in its own channel.
Scenario:Bot runs the join function, a connection is created. It then listens to ready event and create a player to run audio on the connection.
Issue: when bot loops on first element, it instead of waiting for connection to be established (ready) and running the audio, just attaches the listener, then goes to next item. For next item, it again runs the join function which overrieds the previous connection according to docs.
So how would i make bot wait for connection to be ready, wait for audio to be played, since i cant even await the connection.subscribe ):
Code:
3 replies