[英]wait_for() multiple user discord.py
我需要我的機器人等待多個用戶輸入。 例如
如果我在不和諧服務器中調用命令( '!invite @user1 @user2 @user3'
)!
它應該等到所有提到的用戶都說"@mentionme accept"
現在問題是,我可以為一次提及( '!invite @user1'
)做它,但我不能為多個用戶做。 這是我的代碼:
@client.command()
async def invite(ctx,*,message):
mentioned_users = [member for member in message.mentions]#get all mentioned users
def check(message: discord.Message):
return message.channel == ctx.channel and message.author.id in mentioned_users and message.content == f"{ctx.author.mention} accept"
msg = await client.wait_for('message', check=check,timeout=40.0)#wait_for
await ctx.channel.send(f'{member.mention} accepted the invitation!')
它僅適用於一次提及! 還有其他方法可以為多個用戶使用wait_for
函數嗎?
您可以列出所有提及的內容並從中刪除
@bot.command()
async def invite(ctx, *mentions: discord.Member):
await ctx.send('Waiting for everyone to accept the invitation...')
# Converting the tuple to list so we can remove from it
mentions = list(mentions)
def check(message):
if message.channel == ctx.channel and message.author in mentions and message.content.lower() == f'{ctx.author.mention} accept':
# Removing the member from the mentions list
mentions.remove(message.author)
# If the length of the mentions list is 0 means that everyone accepted the invite
if len(mentions) == 0:
return True
return False
await bot.wait_for('message', check=check)
await ctx.send('Everyone accepted the invitation!')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.