Linking guild to a specific member based on dm with bot

I have a bot that's supposed to verify people. Is it possible for the verification to happen under dms? I figure I can't do it unless I have a way to get the guild reference through the message object in bot.on('createMessage', ...)
14 Replies
d.js toolkit
d.js toolkit12mo ago
• 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.
treble/luna
treble/luna12mo ago
its messageCreate and no, you'd have to store the guild id somewhere
royc
royc12mo ago
I tried to
const cachedMemberFromGuild = guild.members.cache.get(message.author.id)
const hasRole = cachedMemberFromGuild.hasRole(roleToCheck)
const cachedMemberFromGuild = guild.members.cache.get(message.author.id)
const hasRole = cachedMemberFromGuild.hasRole(roleToCheck)
But I can't seem to find myself within the guild's cache?
treble/luna
treble/luna12mo ago
how is guild defined and what version are you on
royc
royc12mo ago
const guild = discordBotInstance.guilds.cache.get('1124090488308379758'); "discord.js": "^14.11.0",
treble/luna
treble/luna12mo ago
Its <GuildMember>.roles to get a rolemanager
royc
royc12mo ago
The member that dms the bot is the only member in the server other than the bot It seems to work when I do:
const roleToCheck = guild.roles.cache.find(role => role.name === "Newbie");
const roleToCheck = guild.roles.cache.find(role => role.name === "Newbie");
treble/luna
treble/luna12mo ago
thats indeed how its supposed to be used
royc
royc12mo ago
My problem is that cachedMemberFromGuild is undefined It's not within the cache for some reason Even though the author is present in the server
treble/luna
treble/luna12mo ago
then you'll have to fetch
royc
royc12mo ago
o Wasn't aware of that method
treble/luna
treble/luna12mo ago
Just because the member is in the server doesnt mean they will be cached
royc
royc12mo ago
I see. That makes sense, I assumed that Thanks a lot @luna🌈 (:
treble/luna
treble/luna12mo ago
yw!