最近プログラミングを開始したdiscord.pyボットにmarryコマンドを追加しようとしています。言及されたユーザーがボットに応答できるようにしたいと思います。
現在のコードの時点では、返信するだけです。
@client.command()
async def marry(ctx, member: discord.Member):
await ctx.send(f"{ctx.author.mention} **proposes to** {member.mention} **Do you accept??** "
f"\nRespond with [y(es)/n(o)]")
def check(m):
return m.author == ctx.author
try:
msg = await client.wait_for('message', check=check, timeout=10)
if msg.content.lower() in ['y', 'yes']:
await ctx.send(f"Congratulations! {ctx.author.mention} and {member.mention} are now married to each other!")
elif msg.content.lower() in ['n', 'no']:
await ctx.send(f"Unlucky, maybe another time! {ctx.author.mention}")
else:
await ctx.send("I did not understand that, aborting!")
except asyncio.TimeoutError as e:
print(e)
await ctx.send("Looks like you waited too long.")
ボットが私だけでなく、言及されたユーザー(メンバー:discord.Member)からの次の返信を認識できるようにする方法を知っている人はいますか?
チェックでは、メッセージの作成者がコマンドの引数に渡されているメンバーと同じであるかどうかを簡単にチェックできます。
def check(m):
return m.author == member
また、コマンドが実行されたのと同じチャネルに対して別のチェックを追加することをお勧めします。
これにより、ボットが、言及されたユーザーが行っている他の会話からの返信を取得するのを防ぐことができます。
def check(m):
return ... and m.channel == ctx.channel
参照:
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加