@@ -118,17 +118,18 @@ export class DiscordBot extends Service {
118
118
119
119
// sets both the bot's avatar and the guild's icon
120
120
async setIcon (
121
- path = this . data ? .lastDiscordGuildIcon ?? "resources/discord-guild-icons/default.png" ,
121
+ path = this . data . lastDiscordGuildIcon ?? "resources/discord-guild-icons/default.png" ,
122
122
reason ?: string
123
123
) : Promise < boolean > {
124
124
if ( ! this . ready || ! this . discord . user ) return false ;
125
125
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 ( ) ;
126
131
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 ) ;
132
133
return true ;
133
134
} catch {
134
135
return false ;
@@ -139,32 +140,32 @@ export class DiscordBot extends Service {
139
140
name = this . data . lastDiscordNickName ?? "Meta" ,
140
141
reason ?: string
141
142
) : Promise < boolean > {
142
- if ( ! this . ready || ! this . discord . user || name . length > 22 ) return false ;
143
+ if ( ! this . ready || name . length > 22 ) return false ;
143
144
try {
144
145
const nick = name . charAt ( 0 ) . toUpperCase ( ) + name . slice ( 1 ) ;
146
+ this . data . lastDiscordNickName = this . getNickname ( ) ?? "Meta" ;
147
+ await this . data . save ( ) ;
145
148
await this . getGuild ( ) ?. members . me ?. setNickname ( nick + " Construct" , reason ) ;
146
- if ( this . data ) {
147
- this . data . lastDiscordNickName = nick ;
148
- await this . data . save ( ) ;
149
- }
150
149
return true ;
151
150
} catch {
152
151
return false ;
153
152
}
154
153
}
155
154
155
+ getNickname ( ) : string | undefined {
156
+ return this . getGuild ( ) ?. members . me ?. nickname ?. split ( " " ) [ 0 ] ?? undefined ;
157
+ }
158
+
156
159
async setServerBanner (
157
160
url = this . data ?. lastDiscordBanner ?? null ,
158
161
reason ?: string
159
162
) : Promise < boolean > {
160
163
if ( ! this . ready || ! ( await this . overLvl2 ( ) ) ) return false ;
161
164
try {
162
165
const guild = this . getGuild ( ) ;
166
+ this . data . lastDiscordBanner = guild ?. bannerURL ( ) ?? this . data . lastDiscordBanner ;
167
+ await this . data . save ( ) ;
163
168
await guild ?. setBanner ( url , reason ) ;
164
- if ( this . data && url ) {
165
- this . data . lastDiscordBanner = url ;
166
- await this . data . save ( ) ;
167
- }
168
169
return true ;
169
170
} catch {
170
171
return false ;
0 commit comments