Spaces:
Runtime error

Brozy123 commited on
Commit
e87f6b4
·
verified ·
1 Parent(s): 895f81c

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +22 -12
index.js CHANGED
@@ -2681,23 +2681,33 @@ const pollNeededCount = new Map();
2681
  // Handle reaction removal to decrease count
2682
  client.on('messageReactionRemove', async (reaction, user) => {
2683
  if (user.bot) return;
2684
- if (reaction.partial) await reaction.fetch();
 
 
 
 
2685
 
2686
- if (reaction.emoji.name === '🟩') {
2687
- const guildId = reaction.message.guildId;
2688
- const activePollId = storage.data.active_polls[guildId];
2689
 
2690
- if (reaction.message.id === activePollId) {
2691
- // Safety check: Don't edit if it's a league match (preventing it from becoming !friendly text)
2692
- if (reaction.message.content && reaction.message.content.includes('LEAGUE MATCH')) return;
 
 
 
2693
 
2694
- const count = reaction.count - (reaction.me ? 1 : 0);
2695
- const needed = pollNeededCount.get(guildId) || 6;
2696
 
2697
- // Update the message with current count
2698
- const content = getFriendlyText(guildId, needed);
2699
- await reaction.message.edit({ content: content + `\n\n${count}/${needed} players joined. Waiting for more...` });
 
2700
  }
 
 
2701
  }
2702
  });
2703
 
 
2681
  // Handle reaction removal to decrease count
2682
  client.on('messageReactionRemove', async (reaction, user) => {
2683
  if (user.bot) return;
2684
+
2685
+ try {
2686
+ // Handle partials for both reaction and message to ensure content is available
2687
+ if (reaction.partial) await reaction.fetch();
2688
+ if (reaction.message.partial) await reaction.message.fetch();
2689
 
2690
+ if (reaction.emoji.name === '🟩') {
2691
+ const guildId = reaction.message.guildId;
2692
+ const activePollId = storage.data.active_polls[guildId];
2693
 
2694
+ if (reaction.message.id === activePollId) {
2695
+ const content = reaction.message.content || "";
2696
+
2697
+ // Safety check: Don't edit if it's a league match or NOT a friendly poll
2698
+ if (content.includes('LEAGUE MATCH')) return;
2699
+ if (!content.includes('FRIENDLY')) return;
2700
 
2701
+ const count = reaction.count - (reaction.me ? 1 : 0);
2702
+ const needed = pollNeededCount.get(guildId) || 6;
2703
 
2704
+ // Update the message with current count
2705
+ const baseText = getFriendlyText(guildId, needed);
2706
+ await reaction.message.edit({ content: baseText + `\n\n${count}/${needed} players joined. Waiting for more...` });
2707
+ }
2708
  }
2709
+ } catch (err) {
2710
+ console.error("[REACTION-REMOVE] Error handling removal:", err);
2711
  }
2712
  });
2713