API not returning data

https://gist.github.com/KiraKenjiro/de1460359c1b33dc5f2d55763eae95a2 Inside the Gist, there's a bot that retrieves user information based on their ID. The bot command is functional, so if you use "!info {userid}" in a chat, it will provide you with all the relevant information. However, when I attempt to request the API, it doesn't return any data. Data returned by command:
{
userId: '625393879075651584',
userName: 'kirakenjiro',
displayName: 'kirakenjiro',
discriminator: '0',
bannerHexColor: '242428',
avatarURL: 'https://cdn.discordapp.com/avatars/625393879075651584/d53788b4be06a49798665e9684a282ad.webp',
isAnimatedAvatar: false,
bannerURL: 'https://cdn.discordapp.com/banners/625393879075651584/a_c83b90790bdc19f845db9792f96e2ab7.gif',
isAnimatedBanner: true,
accountCreationDate: 1569175920028,
monitoringSince: 1682242323939,
activities: {
'Genshin Impact': {
name: 'Genshin Impact',
details: null,
state: null,
startPlayTimestamp: 1697974047
}
}
{
userId: '625393879075651584',
userName: 'kirakenjiro',
displayName: 'kirakenjiro',
discriminator: '0',
bannerHexColor: '242428',
avatarURL: 'https://cdn.discordapp.com/avatars/625393879075651584/d53788b4be06a49798665e9684a282ad.webp',
isAnimatedAvatar: false,
bannerURL: 'https://cdn.discordapp.com/banners/625393879075651584/a_c83b90790bdc19f845db9792f96e2ab7.gif',
isAnimatedBanner: true,
accountCreationDate: 1569175920028,
monitoringSince: 1682242323939,
activities: {
'Genshin Impact': {
name: 'Genshin Impact',
details: null,
state: null,
startPlayTimestamp: 1697974047
}
}
Data returned by API:
Response from API:
{}
Response from API:
{}
Can anyone help or run your eyes over this to see if i'm doing anything wrong, I can't unpick it xD
Gist
This is a Discord bot designed to easily retrieve your account deta...
This is a Discord bot designed to easily retrieve your account details using your ID. - index.js
8 Replies
d.js toolkit
d.js toolkit8mo 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! - Marked as resolved by OP
grass
grass8mo ago
where do you define guildId in your app.get(…)? line 182 another probability is that the member isn’t cached in said guild the member is cached in the messagecreate event because discord sends it, but on line 182 theres a probability the member isn’t cached actually, there’d still be some info i’ll look a bit more
Kiɾʌ Kenjiɾø
Turns out it wasnt even entering the try part. But it brings us on to the part that now you get this error Error fetching user: TypeError: Cannot read properties of undefined (reading 'members') at getUserInfo (/Users/kirakenjiro/Desktop/Coding/Plaque/index.js:26:4) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async /Users/kirakenjiro/Desktop/Coding/Plaque/index.js:180:22 Userinfo:null xD So something can't respond correctly Thats responding to this line here
const member = messageClient.guilds.cache
.get(guildID)
.members.cache.get(user.id);
const member = messageClient.guilds.cache
.get(guildID)
.members.cache.get(user.id);
grass
grass8mo ago
either the client isn’t ready or isn’t in that guild make sure you’re passing a string as the id
Kiɾʌ Kenjiɾø
Current i think its being passed as an int
grass
grass8mo ago
then it’s getting truncated
Kiɾʌ Kenjiɾø
Got it, I'll give that a change yep, that was it, Its returning an object now so we're good <3 Thanks so much for the help pistol :D
grass
grass8mo ago
no problem