if user == and str(reaction.emoji) == "\U0001F5BC\U0000FE0F":
channel = client.get_channel(1245390045859549285) #👜-reward-container
# Filter out mention at the start
mention_regex = re.compile(r"^<@&(\d+)> ")
filtered_content = mention_regex.sub("", reaction.message.content, 1)
print(filtered_content)
message = await channel.send(f"{filtered_content} by {reaction.message.author.mention}")
await message.add_reaction("\U0001F5BC\U0000FE0F")
# Below collecting mentions from thumbsup
thumbsuplist = []
message = reaction.message
for reaction in message.reactions:
if reaction.emoji == '👍':
async for user in reaction.users():
if user != client.user:
thumbsuplist.append(user.mention)
joined = ", ".join(thumbsuplist)
print(joined)
# Below BOT creates thread of its own message
thread_name = f"{filtered_content} by {reaction.message.author.display_name}"
thread = await channel.create_thread(name=thread_name, auto_archive_duration=1440, reason=None, type=discord.ChannelType.public_thread)
await thread.send(str(joined))reaction.message.author
尝试找到一种方法来阻止人们在首先添加 \U00002620\U0000fe0f 之前添加此反应。我想出了这个:
elif reaction.emoji == '\U0001F5BC\U0000FE0F':
skull_reaction = discord.utils.get(reaction.message.reactions, emoji='\U00002620\U0000fe0f')
is_skull_user = False
async for skull_user in skull_reaction.users():
if skull_user == user:
is_skull_user = True
break
if not is_skull_user:
await reaction.remove(user)
但这并没有真正起作用 - 机器人仍然添加自己的消息,当有人稍后添加“\U00002620\U0000fe0f”时,什么也没有发生。有人可以帮我吗?
我尝试将第二部分放入代码中,但它没有达到我想要的效果 - 反应被删除,但机器人仍然添加反应,然后什么也没有发生
我对discord py不熟悉,但似乎emoji类不能与字符串进行比较,尝试像之前那样添加一个str,即
elif str(reaction.emoji) == '\U0001F5BC\U0000FE0F':
。
希望这可以解决我们的问题。
另外,根据文档,最后一部分可以简化为:
elif str(reaction.emoji) == '\U0001F5BC\U0000FE0F':
skull_reaction = discord.utils.get(reaction.message.reactions, emoji='\U00002620\U0000fe0f')
# Flatten the async iterator into a list
users = [user async for user in skull_reaction.users()]
# Check if the user is in the list of users who reacted
if user not in users:
await reaction.remove(user)
希望有帮助!