I am getting this following error

if (interaction.commandName == 'gerenciar_auth2') {


//interaction.deferUpdate()
const gg = await AuthConfig.find()


var ssssss = []
for (let iiii = 0; iiii < gg.length; iiii++) {
const element = gg[iiii];

console.log(element.Dono)

if (element.Dono == interaction.user.id) {

const request = await fetch('https://discord.com/api/users/@me', {
method: 'GET',
headers: {
'Authorization': `Bot ${element.Bot.token}`,
'Content-Type': 'application/json',
},
})

const dsdsds = await request.json()

ssssss.push({
name: `🔖 Nome - ${dsdsds.username} | 🧱 ID - ${dsdsds.id}`,
value: `${dsdsds.id}`
})
}

}

if (ssssss.length === 0) {
interaction.respond([{ name: "Nenhum produto registrado foi encontrado", value: "nada" }]);
} else {
interaction.respond(!ssssss.length ? [{ name: `Nenhum produto registrado foi encontrado`, value: `nada` }] : ssssss);
}

}
if (interaction.commandName == 'gerenciar_auth2') {


//interaction.deferUpdate()
const gg = await AuthConfig.find()


var ssssss = []
for (let iiii = 0; iiii < gg.length; iiii++) {
const element = gg[iiii];

console.log(element.Dono)

if (element.Dono == interaction.user.id) {

const request = await fetch('https://discord.com/api/users/@me', {
method: 'GET',
headers: {
'Authorization': `Bot ${element.Bot.token}`,
'Content-Type': 'application/json',
},
})

const dsdsds = await request.json()

ssssss.push({
name: `🔖 Nome - ${dsdsds.username} | 🧱 ID - ${dsdsds.id}`,
value: `${dsdsds.id}`
})
}

}

if (ssssss.length === 0) {
interaction.respond([{ name: "Nenhum produto registrado foi encontrado", value: "nada" }]);
} else {
interaction.respond(!ssssss.length ? [{ name: `Nenhum produto registrado foi encontrado`, value: `nada` }] : ssssss);
}

}
No description
7 Replies
d.js toolkit
d.js toolkit14mo ago
- 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!
Joãozinho
JoãozinhoOP14mo ago
Maybe I'm having a delay in receiving the information, is there anything I can do?
Squid
Squid14mo ago
If you're able to, try fetching the DB data in a different place so you're making a new query to your DB every time you get the autocomplete interaction Also, if you could cache the data returned by fetching the discord user, that would save you API calls in the long run
Joãozinho
JoãozinhoOP14mo ago
How can I resolve this? using mongodb Would you have an example? @Squid
Squid
Squid14mo ago
It's a bit more difficult in commonjs than in esm, but I believe something like:
// top of file
let gg = [];
AuthConfig.find().then(docs => gg = docs)
// top of file
let gg = [];
AuthConfig.find().then(docs => gg = docs)
would populate gg with the DB documents, then you don't have to re-query your db every time a letter in the autocomplete option changes
Joãozinho
JoãozinhoOP14mo ago
but I need to pull it every time to see if there has been a change no?
Squid
Squid14mo ago
yes, you could update that array whenever you make a change elsewhere in your code using a Collection/Map is probably easier when it comes to replacing old data since you can just .set() with the same key and a new value
Want results from more Discord servers?
Add your server