-1

I have ran into an issue with my Discord bot's audit log system. I am trying to make it have have automatic entries for the bot guilds. It cannot take `` strings with ${guild.id} inside.

Here is my code:

client.guilds.cache.forEach(async (guild: any) => {
            guildPrefs = await guildModel.findOne({ GuildID: guild.id }).catch(err => console.log(err));
            let guildId: string = '';
    
            guildId = `${guild.id}`

            await audit(client, {
                `${guild.id}`: {
                    auditlog: guildPrefs.AuditChannel,
                    auditmsg: guildPrefs.AuditChannel,
                    voice: guildPrefs.AuditChannel,
                    trackroles: true
                }
            });
        })
    })

The audit log system I am using is this one: https://www.npmjs.com/package/discord-auditlog but embedded right into the bot.

This is how it shows on VS Code.

nikoszz
  • 163
  • 1
  • 3
  • 13
  • 1
    object literal properties cannot be template strings, use a [computed property](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer#computed_property_names) instead. – ASDFGerte Jun 10 '22 at 20:16

1 Answers1

2

You can use your template literal string in your object key by using bracket notation. Like this:


    [`${guild.id}`]: {
        auditlog: guildPrefs.AuditChannel,
        auditmsg: guildPrefs.AuditChannel,
        voice: guildPrefs.AuditChannel,
        trackroles: true
    }

BrettBI
  • 36
  • 2