Skip to content

Commit bd22f6f

Browse files
authored
Merge pull request #83 from jtsshieh/master
Fetch dormant message if not in cache
2 parents f58e811 + 4e680e5 commit bd22f6f

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"scripts": {
3434
"start": "ts-node-dev --respawn src",
3535
"build": "tsc",
36-
"lint": "prettier --check 'src/**/*.ts'",
37-
"lint:fix": "prettier 'src/**/*.ts' --write "
36+
"lint": "prettier --check \"src/**/*.ts\"",
37+
"lint:fix": "prettier \"src/**/*.ts\" --write "
3838
}
3939
}

src/modules/helpchan.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export class HelpChanModule extends Module {
6060

6161
private getChannelName(guild: Guild) {
6262
const takenChannelNames = guild.channels.cache
63-
.filter(channel => channel.name.startsWith('help-'))
63+
.filter(channel => channel.name.startsWith(this.CHANNEL_PREFIX))
6464
.map(channel => channel.name.replace(this.CHANNEL_PREFIX, ''));
6565
let decidedChannel = channelNames[0];
6666

@@ -174,10 +174,16 @@ export class HelpChanModule extends Module {
174174
if (dormant && dormant instanceof TextChannel) {
175175
await this.moveChannel(dormant, categories.ask);
176176

177-
const lastMessage = dormant.messages.cache
177+
let lastMessage = dormant.messages.cache
178178
.array()
179179
.reverse()
180180
.find(m => m.author.id === this.client.user?.id);
181+
182+
if (!lastMessage)
183+
lastMessage = (await dormant.messages.fetch({ limit: 5 }))
184+
.array()
185+
.find(m => m.author.id === this.client.user?.id);
186+
181187
if (lastMessage) {
182188
// If there is a last message (the dormant message) by the bot, just edit it
183189
await lastMessage.edit(this.AVAILABLE_EMBED);

0 commit comments

Comments
 (0)