#await client.guilds.fetch().commands.set([]) Is returning TypeError Cannot read properties of undef

1 messages · Page 1 of 1 (latest)

orchid sentinel
#

client.guilds.fetch() is not returning what you think it is

indigo thicket
#

because fetch returns a promise

reef loom
#

And i resolve fetch using await

orchid sentinel
#

Your parenthesis are not right

#

And await is ran in the wrong place

indigo thicket
#

(await client.guilds.fetch())...

#

keep in mind this will await the fetch not the set

reef loom
#

I still get the same error

orchid sentinel
#

client.guilds.fetch() is not returning what you think it is

reef loom
#

I just want to remove every single command in guilds

orchid sentinel
#

In your code you're not looping through the guilds

indigo thicket
#

i'm stupid nvm

reef loom
#

Then js for(const guild of (client.guilds.fetch())) { guild.commands.set([]) } would work then

#

?

orchid sentinel
#

Don't forget await

reef loom
#

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?

orchid sentinel
reef loom
#

And guild.commands return undefined

orchid sentinel
#

That's weird..

#

Maybe share the code?

reef loom
#
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

orchid sentinel
#

Use of, not in

#

Also, could you show us guild?

reef loom
#

Just an error if i use of

orchid sentinel
#

If you can't use of, in will only do worse

#

You need of await guild.commands.fetch()

reef loom
#
[
  '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)```
orchid sentinel
#

Looking at the output is obvious

#

You're get partial data. Use fetch() again

#
for(let guild of (await ...)) {
  let trueGuild = await guild.fetch();
  ...
}
reef loom
#

so fetch twice?

orchid sentinel
#

Yes

reef loom
#

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')
    }```
orchid sentinel
#

Oh, first for returns actually a collection

#

So you can't use of right away

reef loom
#

What do you want me to do now then?

orchid sentinel
#

of (await ...).values()

reef loom
#

TypeError: guild.commands is not iterable

orchid sentinel
#

Code again?

reef loom
#
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
orchid sentinel
#

This should work. There may be another way of deleting commands, but I don't know it

reef loom
#
for(const cmd of (await guild.commands.fetch().values)) {
                              ^

TypeError: (intermediate value) is not iterable```
#

...

orchid sentinel
#

.values() shall be outside of await

reef loom
#

Just noticed that

#

It worked

#

Ty <3