#await client.guilds.fetch().commands.set([]) Is returning TypeError Cannot read properties of undef
1 messages · Page 1 of 1 (latest)
because fetch returns a promise
And i resolve fetch using await
(await client.guilds.fetch())...
keep in mind this will await the fetch not the set
I still get the same error
client.guilds.fetch() is not returning what you think it is
I just want to remove every single command in guilds
In your code you're not looping through the guilds
i'm stupid nvm
Then js for(const guild of (client.guilds.fetch())) { guild.commands.set([]) } would work then
?
Don't forget await
Commands is not a thing in the guild then
But how would i then delete every single command i have in the guilds set guildwise?
It is
It still gives TypeError: Cannot read properties of undefined (reading 'set')
And guild.commands return undefined
That's weird..
Maybe share the code?
if(msg.content === "!delete") {
if(!msg.author.id === "575707245849870356") return;
for(const guild of (await client.guilds.fetch())) {
for(const cmd in guild.commands) {
cmd.delete();
}
}
msg.reply('OKAY')
}```
That did not remove anything, cuz guild.commands is logging undefined
of doesn't work, it returns iterable something
Just an error if i use of
If you can't use of, in will only do worse
You need of await guild.commands.fetch()
[
'793090642422661130',
OAuth2Guild {
id: '793090642422661130',
name: 'Heftig Gaming Med Heftige Folk',
icon: 'a_4874f10017a0ed3c79b53b1a341588c4',
features: [],
owner: false,
permissions: Permissions { bitfield: 2199023255551n }
}
]``` Is the first guild logged, then i get error from using `of`
for(const cmd of guild.commands) {
^
TypeError: guild.commands is not iterable
at Client.<anonymous> (C:\Users\sound\Desktop\Moto Music\index.js:67:36)
at processTicksAndRejections (node:internal/process/task_queues:96:5)```
Looking at the output is obvious
You're get partial data. Use fetch() again
for(let guild of (await ...)) {
let trueGuild = await guild.fetch();
...
}
so fetch twice?
Yes
TypeError: guilds.fetch is not a function
if(msg.content === "!delete") {
if(!msg.author.id === "575707245849870356") return;
for(const guilds of (await client.guilds.fetch())) {
const guild = await guilds.fetch()
for(const cmd of guild.commands) {
cmd.delete();
}
}
msg.reply('OKAY')
}```
What do you want me to do now then?
of (await ...).values()
TypeError: guild.commands is not iterable
Code again?
if(msg.content === "!delete") {
if(!msg.author.id === "575707245849870356") return;
for(const guilds of (await client.guilds.fetch()).values()) {
const guild = await guilds.fetch()
console.log(guild.commands)
for(const cmd of guild.commands) {
cmd.delete();
}
}
msg.reply('OKAY')
}```
guild: <ref *2> Guild {
id: '793090642422661130',
name: 'Heftig Gaming Med Heftige Folk',
icon: '4874f10017a0ed3c79b53b1a341588c4',
features: [],
commands: [Circular *1],
members: GuildMemberManager { guild: [Circular *2] },
channels: GuildChannelManager { guild: [Circular *2] },
bans: GuildBanManager { guild: [Circular *2] },
roles: RoleManager { guild: [Circular *2] },
presences: PresenceManager {},
voiceStates: VoiceStateManager { guild: [Circular *2] },
stageInstances: StageInstanceManager { guild: [Circular *2] },
invites: GuildInviteManager { guild: [Circular *2] },
deleted: false,
available: true,
shardId: 0,
splash: null,
banner: null,
description: null,
verificationLevel: 'NONE',
vanityURLCode: null,
nsfwLevel: 'DEFAULT',
discoverySplash: null,
memberCount: 22,
large: false,
applicationId: null,
afkTimeout: 900,
afkChannelId: '853582461070082058',
systemChannelId: '852930337843445770',
premiumTier: 'NONE',
premiumSubscriptionCount: 0,
explicitContentFilter: 'ALL_MEMBERS',
mfaLevel: 'NONE',
joinedTimestamp: 1632238226520,
defaultMessageNotifications: 'ALL_MESSAGES',
systemChannelFlags: SystemChannelFlags { bitfield: 0 },
maximumMembers: 250000,
maximumPresences: 25000,
approximateMemberCount: 22,
approximatePresenceCount: 15,
vanityURLUses: null,
rulesChannelId: null,
publicUpdatesChannelId: null,
preferredLocale: 'en-US',
ownerId: '561985631777980422',
emojis: GuildEmojiManager { guild: [Circular *2] },
stickers: GuildStickerManager { guild: [Circular *2] },
widgetEnabled: false,
widgetChannelId: null
}``` It logs that
So, if we look at https://discord.js.org/#/docs/main/stable/class/GuildApplicationCommandManager?scrollTo=fetch, we can see that guild.commands is a manager, so you need to do a similar thing like for the guilds: fetch and values
This should work. There may be another way of deleting commands, but I don't know it
for(const cmd of (await guild.commands.fetch().values)) {
^
TypeError: (intermediate value) is not iterable```
...
.values() shall be outside of await