Python 向多个标记用户发送消息

Python 向多个标记用户发送消息,python,python-3.x,discord,discord.py,Python,Python 3.x,Discord,Discord.py,如何通过标记向多个用户发送消息 @bot.command(pass_context=True) async def ping(ctx, member: discord.Member): await bot.send_message(member, "Pong...".format(ctx.message)) 因此,当标记单个用户时,上面的代码可以完美地工作?ping@user1,但是当标记多个用户时,如何使其工作?ping@user1@user2 所以,是否有可能使其成为在通道

如何通过标记向多个用户发送消息

@bot.command(pass_context=True)
async def ping(ctx, member: discord.Member):
        await bot.send_message(member, "Pong...".format(ctx.message))
因此,当标记单个用户时,上面的代码可以完美地工作
?ping@user1
,但是当标记多个用户时,如何使其工作
?ping@user1@user2


所以,是否有可能使其成为在通道中而不是脚本中给出的自定义消息。示例:当我们键入
?ping@user1@user2
时,bot应该请求发送消息,当我们添加消息时,它会将消息转发给标记的用户。

消息
类包含一个可以迭代的属性

@bot.command(pass_context=True)
async def ping(ctx):
    for member in ctx.message.mentions:
        await bot.send_message(member, "Pong...".format(ctx.message))

我们可以像在任何其他python函数中一样,为一个命令获取数量可变的参数。如果我们把消息放在第一位,并要求它用引号括起来,那么我们可以在一个命令中完成所有这一切

@bot.command(pass_context=True)
async def ping(ctx, message, *members: discord.Member):
    for member in members:
        await bot.send_message(member, message)
用法:

!ping“这是一条消息”@demory@PatrickHaugh
编辑:

如果要避免强制用户将其
消息
封装在引号中,可以使用


编辑:您错过了
@bot.command
现在它告诉
discord.ext.commands.errors.CommandInvokeError:command引发了一个异常:AttributeError:“Message”对象没有属性“members”
对不起,应该使用
提及
而不是
成员。现在修好了是的。。那我的第二个问题呢?可能吗?示例:当我们键入?ping@.user1@.user2时,bot应该请求发送一条消息,当我们添加消息时,它会将消息转发给标记的用户。在wrapped raise CommandInvokeError(e)中获取错误
从e discord.ext.commands.errors.CommandInvokeError:Command引发了一个异常:AttributeError:“对象没有属性‘wait_from_message’
我确实更改为
wait bot。wait_from_message
wait bot。wait_for_message
但是bot发送消息这样做很好,您可能想改为发送
消息.content
@bot.command(pass_context=True)
async def ping(ctx, *members: discord.Member):
    await bot.say("What message would you like to send?")
    message = await bot.wait_for_message(channel=ctx.message.channel, author=ctx.message.author)
    for member in members:
        await bot.send_message(member, message.content)