avatarURL function is broken?

Hey. I've been making a website with an integration through a Discord bot to get a staff list and its information.
I've came accross an issue with the avatarURL function always returning
null
(I use an alternative for now, displayAvatarURL().

Here the code of the staff route:
const staffList = this.app.config.discordData.staffList;

let staffData: StaffData[] | undefined = this.app._cache.get("staffData");
if (!staffData) {
staffData = [];
const guild = this.app._client.guilds.cache.get(this.app.config.discordData.guildId) || await this.app._client.guilds.fetch(this.app.config.discordData.guildId);
   for (const staff of staffList) {
      const user = guild.members.cache.get(staff) || await guild.members.fetch(staff);
      console.log(user.displayAvatarURL())
      staffData.push({
         staff: user,
         highestRole: user.roles.highest,
         avatar: user.avatarURL() as string
      });
   }

   this.app._cache.set("staffData", staffData);
}

res.render("staff", { title: "Staff", data: staffData });


And here is where I login the bot in the
structures/app.ts
file:
private initializeClient() {
  this._client.on("ready", () => {
    this.logger.info(`Connected to Discord through the bot ${this._client.user?.tag}`, "Discord");
  });

  this._client.login(this.config.discordData.botToken).catch(err => {
    this.logger.error(`Discord connection failed; This may cause an outage.`);
  });
}
Was this page helpful?