Asynchronous user fetching causing issues with embeds and buttons
Hi,
I'm using redis to track the number of messages a user has sent in a thread and I store it in a hash using the userid as the key.
I'm trying to get the user's name to use it as the label for a button.
My code goes over an array of IDs and for each ID it grabs the username and adds a button to an actionrow.
The cache is undefined for some reason so I'm using
interaction.guild?.members.fetch(<user id>)
.
The issue being that awaiting that method causes some weird issues (see the pastebin) and not awaiting it returns nothing as expected. The function it's in is async...
https://pastebin.com/t4sdXMTp26 Replies
• What's your exact discord.js
npm list discord.js
and node node -v
version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.discord.js 14.11.0
node 16 LTS
Here's a code snippet
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
nope
I tried a bunch of things and in every case it's either undefined or it gives the same error
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
I thought about it but haven't tried tbh
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
it's a key so they're strings
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
I'll try that
I probably tried it already though but who knows
give it a sec teamcity needs to build the image
Either my Types are messed up somehow or TS is dumb but it keeps telling me there is no displayname anywhere to be found
it's saying
client.users.fetch
returns a User
not a GuildMember
Despite sounding similar there is a distinct difference between users and members in Discord:
• User: global Discord user data (global avatar, username, tag, id)
• GuildMember: user data associated to a guild (guild, nickname, roles, voice, guild avatar, etc.)
• Conversion: User ➞ GuildMember | GuildMember ➞ User
* Note: Events received in cached guilds will often have both the member and user available, eg.
interaction.user
and interaction.member
I see
nice bot btw
I've changed the var names so it's not as weird
and it's undefined
ah fuk wrong methods
it shouldn't be undefined though
I know the user is in the guild though, do they need to speak or smth to be added to the cache ?
oh that's cool
yeah I checked all that
that's cause my brain is small and I used the wrong method
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
and since it takes forever for docker to build the image I can only sit here and watch as my stupid code builds
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
I'm testing locally using docker
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
it's a complex stack I can't just run the bot
anyways it works now
thanks guys I guess I tried eveything but that
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
it's really cool you should look into it
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View