2021年3月7日星期日

Discord.py send the author of a message information about how many people reacted with a certain reaction

I'm designing a Discord bot that can basically be used throughout your server for different useful tasks, like getting server statistics, DMing a user, and (the topic of this question) making a poll. The code I have is pretty long, so I'm only going to include the imports, important variables, actual code where I'm having a problem, and the end where I run my bot:

from profanity import profanity  import os, random, discord, asyncio, praw    from discord.utils import get  from discord.ext import commands  from dotenv import load_dotenv  from discord.ext.commands import Bot    load_dotenv()  TOKEN = os.getenv('DISCORD_TOKEN')  intents = discord.Intents().all()  intents.members = True  bot = commands.Bot(command_prefix="!!", case_insensitive=True, intents=intents)  devmode = False    @bot.command(name='makePoll', help="Makes a new poll that other users can vote for. Bob Bot may be erroring out because it does not have the highest permissions in the server, so you will need to give it roles to kick users.")  async def makeapoll(ctx,*, message : str):    embed=discord.Embed(title=random.choice(pollNames), description=message, color=0xfcd602)    embed.set_author(name=ctx.author.display_name + " (you can end this poll by reacting with this: 🔴)", url=random.choice(aintsupposedtobeheresunnyboy), icon_url=ctx.author.avatar_url)    mymsg = await ctx.send(embed=embed)    await mymsg.add_reaction('✅')    await mymsg.add_reaction('❌')      def check(reaction, user):      return user == ctx.message.author and str(reaction.emoji) == '🔴'    try:      reaction, user = await bot.wait_for('reaction_add', timeout=60.0, check=check)    except asyncio.TimeoutError:      await ctx.send("Some kind of error occured. Sowwy.")            deletionEmbed = discord.Embed(title="This ends now!", value="It's over, Anakin... I have the high ground", color=0xfcd602)    deletionEmbed.add_field(name="The poll ended!", value=f"The poll's author {ctx.author.display_name} just declared that the poll ended. RIP poll :(\n\nFor those of you who missed the question, here it is: *{message}*\n\n{ctx.author.display_name}, the results of the poll should have been DMed to you right about now. Happy statistical advancement!", inline=False)      await mymsg.edit(embed=deletionEmbed)    bot.run(TOKEN)  

Basically, what I want to do here is that when the author of a poll reacts with a red dot 🔴 (which is used to officially stop the poll), my bot direct-messages the author of the poll with the most recent information about who reacted with any reaction. For example, if two people reacted with a checkmark and three people with a cross, I want the bot to message the poll's author with those stats: 2 checks and 3 crosses. If another user responded with a check after the poll, I don't want to reflect those changes. I tried using the add_raw_reaction function, but that didn't seem to work either. How could I fix this issue?

https://stackoverflow.com/questions/66523149/discord-py-send-the-author-of-a-message-information-about-how-many-people-reacte March 08, 2021 at 09:03AM

没有评论:

发表评论