Reputation: 432
I need my bot to wait for multiple user inputs. for example
if I called a command ('!invite @user1 @user2 @user3'
) in discord server!
It should wait until all the mentioned user says "@mentionme accept"
Now the problem is, I Can Do it for one mention ('!invite @user1'
) but I can't do for multiple users.
here is my code:
@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!')
It works for only one mention! Is there anyother ways to use the wait_for
function for multiple users?
Upvotes: 0
Views: 1106
Reputation: 15689
You can make a list with all the mentions and remove from it
@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!')
Upvotes: 2