代码之家  ›  专栏  ›  技术社区  ›  Climpuright

在对机器人的消息作出反应时发送消息

  •  0
  • Climpuright  · 技术社区  · 2 年前
    @bot.command()
    async def tournament(ctx, arg):
        async def tournament_host(ctx):  
            message = await ctx.channel.send("React to this message to host either an FFA or 2V2 tournament")
            await message.add_reaction("<:ffa:1197727051898163331>")
            await message.add_reaction("<:2v2:1197727046080679996>")
            
            ctx.channel.send(message)
        
        if arg.lower() == "host":
            await tournament_host(ctx)
    

    此命令对 message 两次我想让机器人检测用户对其中一个表情符号的反应,并发送特定的消息。例如,如果用户对:ffa:neneneba表情符号做出反应,机器人程序将说“你正在主持ffa锦标赛”,如果用户对此做出反应:2v2:,则会说“你在主持2v2锦标赛”。

    我还没有尝试任何东西,因为我还没有找到任何关于这个特定问题的东西。

    1 回复  |  直到 2 年前
        1
  •  0
  •   Eriall    2 年前

    退房 this 资源

    尤其是这些线路:

    @bot.command(name="reactiontest")
    async def reaction_test(ctx): # waiting for reactions (✅, ❌) here
        await ctx.send(f"**{ctx.author}**, please react with :white_check_mark: or :x: on this message in 60 seconds")
        
        def check(r: discord.Reaction, u: Union[discord.Member, discord.User]):  # r = discord.Reaction, u = discord.Member or discord.User.
            return u.id == ctx.author.id and r.message.channel.id == ctx.channel.id and \
                   str(r.emoji) in ["\U00002705", "\U0000274c"]
    
        reaction, user = await bot.wait_for('reaction_add', check = check)
    

    然后,使用检查哪个反应 reaction.emoji .