Дискорд-бот написанный на python не обнаруживает реакции
Вкратце у меня есть бот, который по команде копирует сообщение для опроса и пересылает его как embed, так же ставит на это сообщение 2 нужные реакции(галочка и крестик), исходное сообщение удаляет. Так же по еще одной команде бот должен подсчитать реакции на сообщении и показать результат, также в embed, в зависимости от процентов. Все бы ничего, все работает, но мне кажется, что бот не видит реакции вовсе, потому что он всегда показывает один результат вне зависимости от кол-ва реакций. Я проверяла, есть ли у бота все нужные разрешения на сервере и пробовала выводить количество реакций видимых ботом в консоль(второе было безуспешно, поэтому я предполагаю, что бот просто вовсе не видит реакций)
Вот нужная часть кода:
@bot.command(name="poll")
async def echo(ctx, *, message):
picture = None
if len(ctx.message.attachments) > 0:
# Read the first attachment as a file
attachment = ctx.message.attachments[0]
picture_content = await attachment.read()
picture = discord.File(io.BytesIO(picture_content),
filename=attachment.filename)
# Send the echoed message
author_mention = ctx.author.mention
new_embed = discord.Embed(
title="Опрос",
description=f"{author_mention} предлагает: \n{message}",
color=0x5864ec)
if picture:
new_embed.set_image(url=f"attachment://{attachment.filename}")
echoed_message = await ctx.send(embed=new_embed, file=picture)
# Add reactions to the echoed message
await echoed_message.add_reaction('✅') # Check mark
await echoed_message.add_reaction('❌') # Cross
# Delete the original message
await ctx.message.delete()
@bot.command(name="result")
async def result(ctx):
# Get the message that was replied to
replied_message = ctx.message.reference.resolved
if not isinstance(replied_message, discord.Message):
await ctx.send("Не удалось найти сообщение, на которое был дан ответ.")
return
# Get the embed from the replied message
message_embed = replied_message.embeds[0] if replied_message.embeds else None
if message_embed is None or message_embed.description is None:
await ctx.send("Не удалось найти сообщение, на которое был дан ответ.")
return
# Get the reaction counts
check_mark_count = 0
cross_count = 0
for reaction in replied_message.reactions:
if str(reaction.emoji) == '✅':
check_mark_count = reaction.count
print(check_mark_count)
elif str(reaction.emoji) == '❌':
cross_count = reaction.count
print(cross_count)
total_count = check_mark_count + cross_count
# Calculate percentages
if total_count > 0:
check_mark_percentage = round((check_mark_count / total_count) * 100, 2)
cross_percentage = round((cross_count / total_count) * 100, 2)
else:
check_mark_percentage = 0
cross_percentage = 0
# Determine the result
if check_mark_percentage >= 60:
result_text = "**Принято✅**"
elif cross_percentage >= 50:
result_text = "**Отказано❌**"
else:
result_text = "**?⚖️Передано на дальнейшее рассмотрение модерацией?⚖️**"
# Create the result embed
embed = discord.Embed(title="Результат опроса", color=0x5864ec)
embed.add_field(name="Предложение:", value=message_embed.description, inline=False)
embed.add_field(name="Решение:", value=result_text, inline=False)
# Send the result embed and delete the replied message
await ctx.send(embed=embed)
await replied_message.delete()
await ctx.message.delete()