Discord 机器人将跟踪谁在线程中发送了屏幕截图

问题描述 投票:0回答:1

我制作了一个 BOT 来帮助我们处理游戏中的事件。 现在,它确实会附加做出竖起大拇指反应的用户列表,并将他们的名字发布在它在被告知后创建的线程中(由消息作者添加的钱袋反应)。

人们应该在此线程中发送屏幕截图,并在上一条消息中添加钱袋反应。关键是用户通常会忘记添加该反应,我想提醒他们:

  1. 每当有人添加该反应时,BOT 都会通知。
  2. BOT 会在 20 小时后向用户发出 ping 消息,告知他们缺少反应。

这是我的代码部分,机器人:

  • 如果没有头骨反应,就不会让钱袋反应
  • 过滤消息
  • 追加点赞的用户列表
  • 创建线程
  • 在话题中发送用户名

我不确定我是否应该为 on_reaction_add 或 on_thread_create 制作它(我想实现的部分),也许两者都做?有人可以帮我解决这个问题吗?我对 python 还很陌生。

    if user == reaction.message.author and str(reaction.emoji) == "💰":
    channel = client.get_channel(1245389918361092126) #💰-payments

    moneybag_reaction = discord.utils.get(reaction.message.reactions, emoji='💰')
    skull_reaction = discord.utils.get(reaction.message.reactions, emoji='\U00002620\U0000fe0f')
    print("2")

    if not skull_reaction:
        print("3")
        await moneybag_reaction.remove(user)
        return


    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("💰")


    thumbsuplist = []
    message = reaction.message
    for reaction in message.reactions:
        print("2")
        if reaction.emoji == '👍':
            async for user in reaction.users():
                if user != client.user:
                    thumbsuplist.append(user.mention)
    joined = ", ".join(thumbsuplist)
    print(joined)



    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))
python discord.py
1个回答
0
投票

我不明白如何使用

on_thread_create
来完成这项任务。该事件仅在创建线程时发出,并且您正在尝试侦听将屏幕截图发送到线程中的用户。如果您的游戏涉及用户仅将屏幕截图发送到线程中而没有其他内容,那么您可以使用
on_thread_member_join
代替,这样您的机器人就可以知道用户何时加入线程(如果通过发送屏幕截图加入线程)。然后您可以通过立即提及/回复他们来提醒他们做出反应(第 1 步),并设置一个任务在 20 小时内再次提醒他们。

这里有一个片段展示了如何做到这一点:

@client.listener
async def on_thread_member_join(member: discord.ThreadMember) -> None:
    # remind user to react
    await thread.send(f"<@{member.id}> remember to react to the previous message")

    # save the thread and member id somewhere to remind them later 

或者,您可以使用

on_reaction_add
on_raw_reaction_add
。如果您的通道收到大量消息,请使用
on_raw_reaction_add
,因为仅当消息位于内部消息缓存中时才会发出
on_reaction_add

要处理提醒(如果是 20 小时后提醒),请查看 discord.ext.tasks,您可以将提醒存储在数据库中并运行循环来获取并处理指定时间间隔内的提醒。

© www.soinside.com 2019 - 2024. All rights reserved.