在哪里放置 Discord JS Bot Presence 代码?

Where to put Discord JS Bot Presence code?

所以我试图将代码放入我的 Discord 机器人中,为它提供自定义状态供用户查看,然后当我找到代码时,我不知道该把它放在哪里。
这是代码:我应该把它放在哪里?

    * Sets the full presence of the client user.
   * @param {PresenceData} data Data for the presence
   * @returns {Promise<ClientUser>}
   * @example
   * // Set the client user's presence
   * client.user.setPresence({ game: { name: 'with discord.js' }, status: 'idle' })
   *   .then(console.log)
   *   .catch(console.error);
   */
  setPresence(data) {
    return new Promise(resolve => {
      let status = this.localPresence.status || this.presence.status;
      let game = this.localPresence.game;
      let afk = this.localPresence.afk || this.presence.afk;

      if (!game && this.presence.game) {
        game = {
          name: this.presence.game.name,
          type: this.presence.game.type,
          url: this.presence.game.url,
        };
      }

以上代码属于 ClientUser.js 文件。它可能属于其他文件,例如 Presence.js

你可以把它放在任何地方,但很可能你想把它放在你的 ready 活动中,比如

    client.on('ready', () => {
        client.user.setPresence({ game: { name: 'with discord.js' }, status: 'idle' })
        console.log(`${client.user.username} is up and running!`);
    })
client.on('ready', () => {
    console.log(`Logged in as ${client.user.tag}!`);

    client.user.setPresence({
        status: 'online',
        activity: {
            name: ".help",
            type: "PLAYING"
        }
    });
});

状态可以是 onlineidledndinvisible。 (dnd 是请勿打扰)

这里的另一个变量是activity。它是一组两个变量:nametype.

名称是机器人正在做什么。这是您选择的字符串。类型是帮助它显示为的另一件事。它可以是 "PLAYING""STREAMING""WATCHING""LISTENING""CUSTOM_STATUS"