首页 > 解决方案 > Discord.py 收集表情符号反应并利用它们制作功能

问题描述

每当用户对检查表情符号做出反应或他们对 x 做出反应时,我都会尝试创建一个函数。所以基本上我检查用户是否有电话,如果用户有电话,那么你可以打电话给他们。机器人在 dms 中发送一条消息,并用检查和斧头做出反应,如果您单击检查我想要一个功能发生,我该怎么做?

    @commands.command()
@commands.cooldown(1,120,commands.BucketType.user)
async def call(self, ctx, member : discord.Member):
    phone = False
    users = await bank_data()
    user = ctx.author
    client = discord.Client
    try:
        bag=users[str(user.id)]["bag"]
    except:
        bag=[]
    for item in bag:
        name = item["item"]
        if name == "phone":
            phone = True
    if phone == False:
        await ctx.reply("You must buy a phone to call someone idiot.") 
    if phone == True:
        try:
            targetBag = users[str(target.id)]["bag"]
        except:
            targetBag=[]
        targetPhone = False
        if target:
            for item in targetBag:
                name = item["item"]
                if name =="phone":
                    targetPhone = True
            if targetPhone == False:
                await ctx.reply("Attempted user to call does not have a phone.")
            if targetPhone == True:
                channel = await target.create_dm()
                emojis=['✅', '❌']
                confirmEmoji = '✅'
                message=await channel.send(f"{ctx.author} is calling you. Do you want to answer?")
                for emoji in emojis:
                    await message.add_reaction(emoji)

标签: pythondiscorddiscord.py

解决方案


您可以在wait_for()这种情况下使用 。创建一个响应变量,以便您可以检查并使用响应来接听电话或拒绝接听电话。您可以在此处阅读更多相关信息 - https://discordpy.readthedocs.io/en/stable/api.html#discord.Client.wait_for

wait_for()在您的情况下,您可以传递不同类型的事件reaction_add

希望这有帮助:D


推荐阅读