@client.command() 异步 def ra(ctx):
embed = discord.Embed(
colour=discord.Colour.blue(),
title="RIDEALONG REQUEST",
description=str(ctx.author.mention) + " IS REQUESTING A RIDEALONG IN SERVER."
)
embed.add_field(name="For FTOs", value="Please react to this message to accept the Ride-Along.", inline=False)
embed.timestamp = datetime.utcnow()
embed.set_footer(text= "This message will automatically delete in two hours")
msg = await ctx.send(embed=embed, delete_after=7200)
await msg.add_reaction('✔️')
await msg.add_reaction('❌')
await ctx.message.delete()
答案 0 :(得分:1)
您可以使用不同的事件。大多数情况下我们wait_for
是reaction_add
。
我个人使用以下内容:
try:
reaction, user = await client.wait_for('reaction_add')
while user == client.user:
reaction, user = await client.wait_for('reaction_add')
if str(reaction.emoji) == "YourEmoji":
# Do what you want to do
except Exception: # Timeout can be added for example
return
在这里,我们检查机器人反应是否不算作有效反应,而是算作用户反应。
完整代码如下:
@client.command()
async def ra(ctx):
embed = discord.Embed(
colour=discord.Colour.blue(),
title="RIDEALONG REQUEST",
description=str(ctx.author.mention) + " IS REQUESTING A RIDEALONG IN SERVER.")
embed.add_field(name="For FTOs", value="Please react to this message to accept the Ride-Along.", inline=False)
embed.timestamp = datetime.datetime.utcnow()
embed.set_footer(text="This message will automatically delete in two hours")
msg = await ctx.send(embed=embed, delete_after=7200)
await msg.add_reaction('✔️')
await msg.add_reaction('❌')
await ctx.message.delete()
try:
reaction, user = await client.wait_for('reaction_add')
while user == client.user:
reaction, user = await client.wait_for('reaction_add')
if str(reaction.emoji) == "✔️":
# Do what you want to do
except Exception:
return