如果先添加反应 A,则 Discord Bot 允许反应 B

问题描述 投票:0回答:1
@client.event
async def on_reaction_add(reaction, user):
    if client.user == user:
        return
    if user != reaction.message.author and reaction.emoji not in ('🦵', '👍'):
        await reaction.remove(user)

现在我只允许会员总共只使用 2 个反应。 我想要的是让他们与第一个('🦵')反应,这样他们就可以与另一个('👍')反应,否则机器人会删除它。 有人可以帮我吗?听起来很容易,但我已经累坏了。

请不要使用任何按钮。

我已经尝试过为用户中的用户使用 asyncio,但没有成功。 我不太确定如何在代码中调用常规反应用户,并且根本不知道该怎么做:(

@client.event
async def on_reaction_remove(reaction, user):
    if client.user == user:
        return
    print("1")
    if user and (reaction.emoji) in ("🦵", "👍"):
        channel = client.get_channel(1245472750164906084)
        print("2")
        await channel.send(f"{user.display_name} removed reaction {reaction.emoji}")
        print("3")

这不起作用 - 甚至无法打印 1

python discord.py
1个回答
0
投票

您为什么使用

on_reaction_remove
事件?您问题的逻辑只需要您的机器人在添加
🦵
反应时检查用户是否已经对
👍
作出反应。

import discord


@client.event
async def on_reaction_add(reaction: discord.Reaction, user: discord.User):
    if client.user == user:
        return
    elif user != reaction.message.author and reaction.emoji not in ('🦵', '👍'):
        await reaction.remove(user)
    elif reaction.emoji == '👍':
        leg_reaction = discord.utils.get(reaction.message.reactions, emoji='🦵')
        is_leg_user = False
        async for leg_user in leg_reaction.users():
            if leg_user == user:
                is_leg_user = True
                break
        if not is_leg_user:
            await reaction.remove(user)
© www.soinside.com 2019 - 2024. All rights reserved.