Linked Questions

Popular Questions

I'm trying to make a starboard-like cog in my bot.

Say a message receives one "star" emoji reaction, the bot will take the message and embed it in the starboard channel, the embed shows the content, the channel, and the user who starred it.

However, when the message receives more than one reaction, can I edit the embedded message to show the additional users?

    @commands.Cog.listener()
    async def on_raw_reaction_add(self, payload):
        if str(payload.emoji) == "\U00002B50":
            channel = self.bot.get_channel(payload.channel_id)
            message = await channel.fetch_message(payload.message_id)

            user = self.bot.get_user(payload.user_id)
            if user.bot:
                return
            
            reactions = discord.utils.get(message.reactions, emoji=payload.emoji.name)
            if reactions and reactions.count == 1:
                starboard_channel_id = 1141847109528735866
                starboard_channel = self.bot.get_channel(starboard_channel_id)

                if starboard_channel:
                    reacted_users = await reactions.users().flatten()
                    mentions = ' '.join([u.mention for u in reacted_users])
                    print(mentions)
                
                if starboard_channel:
                    embed =  discord.Embed(description=message.content,color=discord.Color.blurple())
                    embed.set_author(name=message.author.display_name)
                    embed.add_field(name="Starred by", value=mentions, inline=True)
                    embed.add_field(name="Starred in", value=channel.mention, inline=True)
                    embed.add_field(name="Jump to message", value=f"[Click here]({message.jump_url})", inline=True)
                    embed.set_thumbnail(url=message.author.avatar)
                    await starboard_channel.send(embed=embed)
                    
                    if reactions and reactions.count > 1:
                        updated_users = await reactions.users().flatten()
                        updated_mentions = ' '.join([u.mention for u in updated_users])
                        print(updated_mentions)

                        embed_new = discord.Embed(description=message.content,color=discord.Color.blurple())
                        embed_new.set_author(name=message.author.display_name)
                        embed_new.add_field(name="Starred by", value=updated_mentions, inline=True)
                        embed_new.add_field(name="Starred in", value=channel.mention, inline=True)
                        embed_new.add_field(name="Jump to message", value=f"[Click here]({message.jump_url})", inline=True)
                        embed_new.set_thumbnail(url=message.author.avatar)
                        await starboard_channel.edit(embed=embed_new)

I tried adding print statements to print the initial mention of the user who starred the message, and it prints. The second print statement does not, referring to the print(updated_mentions.

Related Questions