diff --git a/src/matrixeventprocessor.ts b/src/matrixeventprocessor.ts index cfc829aa10dfdb5a90f27f2ebd9ee13e7a2bee56..b720f90a59d18f24f02705cc0dec918225c73d1f 100644 --- a/src/matrixeventprocessor.ts +++ b/src/matrixeventprocessor.ts @@ -495,7 +495,7 @@ export class MatrixEventProcessor { displayname: string, avatar_url: string|undefined }) { let displayName = sender; - let avatarUrl; + let avatarUrl: string | undefined = undefined; // Are they a discord user. if (this.bridge.isNamespacedUser(sender)) { @@ -517,22 +517,21 @@ export class MatrixEventProcessor { // Let it fall through. } - if (profile) { - if (profile.displayname && - profile.displayname.length >= MIN_NAME_LENGTH && - profile.displayname.length <= MAX_NAME_LENGTH) { - displayName = profile.displayname; - } + if (profile?.displayname && + profile.displayname.length >= MIN_NAME_LENGTH && + profile.displayname.length <= MAX_NAME_LENGTH) { + displayName = profile.displayname; + } - if (profile.avatar_url) { - avatarUrl = this.bridge.botClient.mxcToHttpThumbnail( - profile.avatar_url, - DISCORD_AVATAR_WIDTH, - DISCORD_AVATAR_HEIGHT, - "scale", - ); - } + if (profile?.avatar_url) { + avatarUrl = await this.bridge.botClient.mxcToHttpThumbnail( + profile.avatar_url, + DISCORD_AVATAR_WIDTH, + DISCORD_AVATAR_HEIGHT, + "scale", + ); } + embed.setAuthor( displayName.substring(0, MAX_NAME_LENGTH), avatarUrl,