当机器人加入 discord.js v13 时,如何从服务器获取 guild.id

How do I get the guild.id from the server when the bot joins discord.js v13

正如标题所说,当机器人刚加入时,我不知道如何从服务器获取 guild.id。 我需要 guildCreate 事件中的 guild.id。

编辑: 我的问题是我的代码中有一个拼写错误,但没有被标记为错误。 因为我需要 guild.id 作为数据库条目,所以我正在使用 MySQL 并且我遗漏了一个“`”。感谢大家的帮助。

只需将guild作为guildCreate的参数:

client.on('guildCreate', (guild) => {
  const { id } = guild;
  // do something with id
});