@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: 表情符号做出反应,机器人会说“您正在举办 FFA 锦标赛”,如果用户对 :2v2: 做出反应,则会说“您正在举办 2v2 锦标赛”。
我还没有尝试过任何东西,因为我还没有找到针对这个特定问题的任何内容。
查看这个资源。
特别是这些行:
@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
检查哪个反应。