删除对我们自己消息的反应

时间:2019-11-09 18:57:05

标签: python-3.x discord discord.py discord.py-rewrite

我希望我的机器人删除对我们自己消息的反应

@client.event
async def on_raw_reaction_add(payload):
    if payload.channel_id == 614467771866021944 or 469197781308014593:
        if payload.emoji.name == "dev":
            if payload.channel_id == 614467771866021944:
                channel = client.get_channel(614467771866021944)
            if payload.channel_id == 469197781308014593:
                channel = client.get_channel(469197781308014593)
            message = await channel.fetch_message(payload.message_id)
            emoji = get(channel.guild.emojis, name=payload.emoji.name)
            reaction = get(message.reactions, emoji=emoji)
            async for user in reaction.users():
                if user == message.author:
                    # delete the reaction

1 个答案:

答案 0 :(得分:0)

if payload.channel_id == 614467771866021944 or 469197781308014593:

此行将始终被评估为True,因为469197781308014593始终为True,如注释中所述,在这种情况下,您应使用in关键字。

        if payload.channel_id == 614467771866021944:
            channel = client.get_channel(614467771866021944)
        if payload.channel_id == 469197781308014593:
            channel = client.get_channel(469197781308014593)

可以简称为

        channel = client.get_channel(payload.channel_id)

最终代码:

@client.event
async def on_raw_reaction_add(payload):
    if payload.channel_id in [614467771866021944, 469197781308014593]:
        if payload.emoji.name == "dev":
            channel = client.get_channel(payload.channel_id)
            message = await channel.fetch_message(payload.message_id)
            emoji = get(channel.guild.emojis, name=payload.emoji.name)
            reaction = get(message.reactions, emoji=emoji)
            async for user in reaction.users():
                if user == message.author:
                    await reaction.remove(user)