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 toolkit2y 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/luna2y ago
its messageCreate and no, you'd have to store the guild id somewhere
royc
roycOP2y 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/luna2y ago
how is guild defined and what version are you on
royc
roycOP2y ago
const guild = discordBotInstance.guilds.cache.get('1124090488308379758'); "discord.js": "^14.11.0",
treble/luna
treble/luna2y ago
Its <GuildMember>.roles to get a rolemanager
royc
roycOP2y 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/luna2y ago
thats indeed how its supposed to be used
royc
roycOP2y 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/luna2y ago
then you'll have to fetch
royc
roycOP2y ago
o Wasn't aware of that method
treble/luna
treble/luna2y ago
Just because the member is in the server doesnt mean they will be cached
royc
roycOP2y ago
I see. That makes sense, I assumed that Thanks a lot @luna🌈 (:
treble/luna
treble/luna2y ago
yw!
Want results from more Discord servers?
Add your server