#Cannot read properties of undefined client.guilds

1 messages Β· Page 1 of 1 (latest)

wanton sinew
#

Hello there πŸ™‚
Trying to assign a role to a user. When i put

console.log(client.guilds.cache);

on top of my code, it logs the guilds cache.
When it comes to the part where i actually need it,

 const tripsitGuild = await client.guilds.cache.get(discordGuildId);
        const roleIrcVerified = tripsitGuild.roles.cache.find(
          role => role.id === roleIrcVerifiedId,
        );

it says Cannot read properties of undefined (reading 'guilds')

#

Thanks in advance for any advice that might help πŸ™‚ ❀️

deft cosmos
#

client is undefined so you not defined it in that file maybe? if you are using the messageCreate event or interactionCreate you can use message.client or interaction.client or pass it threw the function as param ( also the await before client.guilds.cache.get() is not needed and you can use roles.cache.get("roleid")

wanton sinew
#

I have the commands separated into their own files

deft cosmos
#

yes thats why client is not defined their ig, you can show a command file code maybe so we can find out if its that whats wrong

wanton sinew
#

the console.log statement in the first line of the function works for some reason

deft cosmos
#

yes you have no client in that file because you only pass interaction threw your execute function , so you can use interaction.client.guilds.cache.get() to access your client and use it , or pass it threw the params execute(interaction, client) => and in your command handler also

wanton sinew
deft cosmos
#

i mean the output

wanton sinew
#

again too long for a message though