client.once('ready', () => {
console.log("STARTTTTTTT");
const guildId = // ??
const guild = client.guilds.cache.get(guildId)
let commands
if (guild) {
commands = guild.commands
} else {
commands = client.application?.commands
}
commands?.create({
name: "lena",
description: "LENAAAAAAAAAA",
options: [
{
name: 'name',
description: "LENAAAAAAA",
required: true,
type: Discord.Constants.ApplicationCommandOptionTypes.STRING
},
{
name: 'text',
description: "LENAAA",
required: false,
type: Discord.Constants.ApplicationCommandOptionTypes.STRING
},
]
})
})
In line 4 you can see that I need to define on Guild Ids, the question I am asking myself is how do I access all of them, how do I access all the servers that my discord bot is on?
Or is there a simpler way?
Using client.guilds.cache
console.log(client.guilds.cache) // Collection of all guild objects
To get it as an array:
console.log([...client.guilds.cache.values()])
To get all IDs
console.log(client.guilds.cache.map(g => g.id)) // Array of IDs