check if channel id is in guild id

Help pls I want to check if channel id is in guild id without running a command node = v18.13.0 djs = 14.8.0 My code (Dose not work (its for a command but i want it to run without a command))
const guild = client.guilds.resolve(guildId);
if (guild.channels.cache.get(ids.chat) === undefined) {
console.log('not there');
}
else {
console.log('its there');
}
const guild = client.guilds.resolve(guildId);
if (guild.channels.cache.get(ids.chat) === undefined) {
console.log('not there');
}
else {
console.log('its there');
}
10 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Awashcard0
Awashcard0OP2y ago
Hello?
Squid
Squid2y ago
What do you mean by "Dose not work"?
Awashcard0
Awashcard0OP2y ago
I found the code on stack Overflow and I think it's meant to be ran in a command file not a on-demand file found the code on stack Overflow and I think it's meant to be ran in a command. I want to run it every 10 seconds not from a command.
Squid
Squid2y ago
As long as you have access to a ready Client instance, it doesn't matter where the code goes since it doesn't rely on any Interactions
Awashcard0
Awashcard0OP2y ago
when I run it this happens
if (guild.channels.cache.get(ids.chat) === undefined) {
^

TypeError: Cannot read properties of null (reading 'channels')
at Object.<anonymous> (C:\Users\awash\Downloads\all mod\index.js:80:11)
at Module._compile (node:internal/modules/cjs/loader:1218:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1272:10)
at Module.load (node:internal/modules/cjs/loader:1081:32)
at Module._load (node:internal/modules/cjs/loader:922:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:23:47

Node.js v18.13.0
if (guild.channels.cache.get(ids.chat) === undefined) {
^

TypeError: Cannot read properties of null (reading 'channels')
at Object.<anonymous> (C:\Users\awash\Downloads\all mod\index.js:80:11)
at Module._compile (node:internal/modules/cjs/loader:1218:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1272:10)
at Module.load (node:internal/modules/cjs/loader:1081:32)
at Module._load (node:internal/modules/cjs/loader:922:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:23:47

Node.js v18.13.0
Squid
Squid2y ago
That means guild is null
d.js docs
d.js docs2y ago
• The provided id is incorrect (copy role ids from context menus, not message mentions) • The client does not have this structure cached (try fetching instead) • The client is not yet ready (move the code into any event listener callback)
Awashcard0
Awashcard0OP2y ago
I the the gild this way const guild = client.guilds.resolve(guildId);
Squid
Squid2y ago
resolve returns null when one of these things occurs ^
Want results from more Discord servers?
Add your server