#Threads with unbalanced reactions return incorrect reaction values

1 messages Β· Page 1 of 1 (latest)

wide patio
#

Linked vaguely to my previous thread about reactions failing (in that it is the same code): except different problem!
I'm fetching reactions using starting_message.reactions, but the list of Reaction objects is incorrect when a user has reacted to one of the bot-provided reactions...

For example, the list should have two reactions here, with a πŸ”΄ with count=2 and a 🟒 with count=1. However, all that appears is one πŸ”΄ - [<Reaction emoji=':red_circle:' me=False count=1>].

Unsure why this is happening - any help would be great!

rare solstice
#

does on_reaction fire when you do that?

wide patio
#

A quick check has revealed that as mentioned, this occurs only when there is an imbalance. If there are two of each circle, [<Reaction emoji=':green_circle:' me=True count=1>, <Reaction emoji=':red_circle:' me=True count=1>] both are returned as 1....

rare solstice
wide patio
wide patio
#

.rtfm on_reaction

wide patio
#

I can actually for my use case patch this out manually, but it seems odd that it happens

rare solstice
#

I'll test it today

wide patio
rare solstice
#

I wasn't able to test it yet but I will soon, can you give me the minimal reproducible code + instructions how to reproduce it

wide patio
# rare solstice I wasn't able to test it yet but I will soon, can you give me the minimal reprod...

i suppose the minimum reproducible code would be something along the lines of (sorry not at PC, may be slightly inaccurate but you get the gist):

@bot.event
async def on_reaction_add(reaction, user):
    print(reaction.message.reactions)    

then create a forum channel, add a new thread, and on the starting message put reactions so that they are first in balance, then out of balance
i.e. 1 of each, then 2 of one and 1 of another

#

you might need to get the bot itself to add reactions so that you can get an out-of-balance condition

rare solstice
#

works fine for me? first event is the bot adding the circle, second is me adding the secondary reaction, third is me adding to the bot-created reaction

#

@wide patio

wide patio
rare solstice
#

yes

wide patio
#

or ```py
async with bot:
bot.start(token)

#

as is the recommended

rare solstice
#

same result

wide patio
#

give me a sec to check my actual code

wide patio
#

I'm using a list comprehension to filter the results

#

[react for react in reactions if react.emoji == '🟒'][0].count

rare solstice
#

for the bot added reaction?

wide patio
rare solstice
#

yea but the green circle is the bot added one?

wide patio
#

so if potentially you try a message where the bot adds two reactions, then you additionally react to one?

rare solstice
#

adding green circle

#

adding to bot-reacted red circle

wide patio
rare solstice
#

yea

wide patio
#

can you try red and green circle added by bot?

rare solstice
#

same exact result

wide patio
#

that is weird...

#

sorry could you try one more thing - have the reaction printing bit (currently in the event listener) in a slash command?

rare solstice
#

same result

wide patio
#

ok

#

thanks for trying to reproduce anyway

#

i'm still fairly sure its not an error in my code as i can't see anything that could affect that...

#

but i will do some more debugging on my copy when i can :)

#

thanks!

rare solstice
#

np

pallid quiver
#

@wide patio Not too sure what you're trying to do, so this might not work, but have you tried using on_raw_reaction_add and filtering by message id/channel id/user id/etc?

#

Happy to give you a hand with that if it sounds like it'd work

wide patio
pallid quiver
#

What is it you're trying to do if you don't mind me asking?

wide patio
#

to summarise: I'm trying to count the number of reactions of a certain emoji on a message. the bot will add a green circle and a red circle to the message, and i want to then at a later time fetch the reactions and see whether users have added more green or more red circles to the message

pallid quiver
#

Hm. Give me a minute to write a little test script

#

Might have an idea for something like that

wide patio
#

Just to note, as it says on the thread, the problem is that I only get (from .reactions) the emoji with the higher count

#

Which is fine for my use case as thats the only one I technically need

#

But I would rather have the raw count data, especially as this doesn't seem intended and I'd rather not rely on broken functionality

pallid quiver
#

So, you send a message with certain reactions and then after a set time you want to know how many of each reaction there are?

wide patio
#

i await message.add_reaction() twice at an earlier stage (when the message is sent) and later i get message.reactions

pallid quiver
#

Okay, 2 seconds :D

#

What's the code you're currently using?

#

A minimal recreation is fine, I don't expect you to send your whole bot code haha

wide patio
#

well its kinda difficult to extract

pallid quiver
#

Allg, I'll manage without

wide patio
#

do you mean for the fetching of the reactions?

wide patio
#

@pallid quiver

pallid quiver
#

I meant for like the system as a whole

#

In terms of how you send the message & add reactions and then later count them

#

Was going to see if I could tweak that rather than make something new just for your simplicity sake

wide patio
#

give me a sec then :)

pallid quiver
#

Allg, take ur time :D

wide patio
#
  thread = await channel.create_thread(name=name, embed=embed, reason='Created WA proposal thread. Automatic action by Assembly bot.') # Create a thread using the embed earlier
        logger.info('Thread created')

        message = thread.starting_message # get the message just sent
        logger.debug('Message object found')

        await message.add_reaction('🟒') # add required reactions
        await message.add_reaction('πŸ”΄')
        logger.info('Reactions added')

adds reactions
(channel is a valid ForumChannel object)

#

oops indentation is broken sry

#
 reactions = bot.get_channel(thread).starting_message.reactions

        logger.debug(reactions)

        green = [react for react in reactions if react.emoji == '🟒'][0].count
        red = [react for react in reactions if react.emoji == 'πŸ”΄'][0].count

gets reactions
(thread is the .id attribute of a valid Thread object)
also indentation is broken again lol

pallid quiver
#

Is this by chance for like a suggestion upvote/downvote system?

wide patio
pallid quiver
#

I think I have something mostly similar written for a bot of mine actually

#

I'm happy to lend you the code

#

2 mins

#

It adds a message context command to the message Apps menu named "Suggest This"

#

It then creates a thread with both the emojis defined as GREEN_EMOJI and RED_EMOJI

#

You can run /result in a thread to count the votes for each reaction

#

Just an fyi though I made it exclude the bot default reactions so you can edit lines 82 and 84 to remove that logic if you want :D

#

Let me know if you have any issues with it

wide patio
wide patio
rare solstice
#

marvellous