Skip to content

Commit f39a79a

Browse files
Techbot121Meta Construct
authored andcommitted
save old then set it 🤦
1 parent 51d8822 commit f39a79a

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

app/services/discord/index.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,18 @@ export class DiscordBot extends Service {
118118

119119
// sets both the bot's avatar and the guild's icon
120120
async setIcon(
121-
path = this.data?.lastDiscordGuildIcon ?? "resources/discord-guild-icons/default.png",
121+
path = this.data.lastDiscordGuildIcon ?? "resources/discord-guild-icons/default.png",
122122
reason?: string
123123
): Promise<boolean> {
124124
if (!this.ready || !this.discord.user) return false;
125125
try {
126+
const guild = this.getGuild();
127+
if (!guild) return false;
128+
this.data.lastDiscordGuildIcon =
129+
this.discord.user.avatarURL() ?? guild.iconURL() ?? this.data.lastDiscordGuildIcon;
130+
await this.data.save();
126131
await this.discord.user.setAvatar(path);
127-
await this.getGuild()?.setIcon(path, reason);
128-
if (this.data) {
129-
this.data.lastDiscordGuildIcon = path;
130-
await this.data.save();
131-
}
132+
await guild.setIcon(path, reason);
132133
return true;
133134
} catch {
134135
return false;
@@ -139,32 +140,32 @@ export class DiscordBot extends Service {
139140
name = this.data.lastDiscordNickName ?? "Meta",
140141
reason?: string
141142
): Promise<boolean> {
142-
if (!this.ready || !this.discord.user || name.length > 22) return false;
143+
if (!this.ready || name.length > 22) return false;
143144
try {
144145
const nick = name.charAt(0).toUpperCase() + name.slice(1);
146+
this.data.lastDiscordNickName = this.getNickname() ?? "Meta";
147+
await this.data.save();
145148
await this.getGuild()?.members.me?.setNickname(nick + " Construct", reason);
146-
if (this.data) {
147-
this.data.lastDiscordNickName = nick;
148-
await this.data.save();
149-
}
150149
return true;
151150
} catch {
152151
return false;
153152
}
154153
}
155154

155+
getNickname(): string | undefined {
156+
return this.getGuild()?.members.me?.nickname?.split(" ")[0] ?? undefined;
157+
}
158+
156159
async setServerBanner(
157160
url = this.data?.lastDiscordBanner ?? null,
158161
reason?: string
159162
): Promise<boolean> {
160163
if (!this.ready || !(await this.overLvl2())) return false;
161164
try {
162165
const guild = this.getGuild();
166+
this.data.lastDiscordBanner = guild?.bannerURL() ?? this.data.lastDiscordBanner;
167+
await this.data.save();
163168
await guild?.setBanner(url, reason);
164-
if (this.data && url) {
165-
this.data.lastDiscordBanner = url;
166-
await this.data.save();
167-
}
168169
return true;
169170
} catch {
170171
return false;

0 commit comments

Comments
 (0)