fix bug that reactions are not loaded after restart
the message needed to be fetched again. Probably something with caches..
This commit is contained in:
		@@ -130,7 +130,7 @@ export class ExtendedClient extends Client {
 | 
			
		||||
      const textChannel: TextChannel = this.getAnnouncementChannelForGuild(guild.id)
 | 
			
		||||
      this.announcementRoleHandlerTask.set(guild.id, schedule("*/10 * * * * *", async () => {
 | 
			
		||||
        const requestId = uuid()
 | 
			
		||||
        const messages = (await textChannel.messages.fetchPinned()).filter(message => message.cleanContent.includes("[announcement]"))
 | 
			
		||||
        const messages = (await textChannel.messages.fetchPinned()).filter(message => message.cleanContent.includes("[initial]"))
 | 
			
		||||
 | 
			
		||||
        if (messages.size > 1) {
 | 
			
		||||
          logger.error("More than one pinned announcement Messages found. Unable to know which one people react to. Please fix!", { guildId: guild.id, requestId })
 | 
			
		||||
@@ -138,9 +138,11 @@ export class ExtendedClient extends Client {
 | 
			
		||||
          logger.error("Could not find any pinned announcement messages. Unable to manage roles!", { guildId: guild.id, requestId })
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        const message = messages.at(0)!
 | 
			
		||||
        const message = await messages.at(0)!.fetch()
 | 
			
		||||
        //logger.debug(`Message: ${JSON.stringify(message, null, 2)}`, { guildId: guild.id, requestId })
 | 
			
		||||
 | 
			
		||||
        const reactions = await message.reactions.resolve("🎫")
 | 
			
		||||
        const reactions = message.reactions.resolve("🎫")
 | 
			
		||||
        //logger.debug(`reactions: ${JSON.stringify(reactions, null, 2)}`, { guildId: guild.id, requestId })
 | 
			
		||||
        if (reactions) {
 | 
			
		||||
          manageAnnouncementRoles(message.guild, reactions, requestId)
 | 
			
		||||
        } else {
 | 
			
		||||
@@ -149,6 +151,7 @@ export class ExtendedClient extends Client {
 | 
			
		||||
      }))
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public stopAnnouncementRoleBackgroundTask(guild: string | Guild, requestId: string) {
 | 
			
		||||
    const guildId: string = guild instanceof Guild ? guild.id : guild
 | 
			
		||||
    const task: ScheduledTask | undefined = guild instanceof Guild ? this.announcementRoleHandlerTask.get(guild.id) : this.announcementRoleHandlerTask.get(guild)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user