Python 如何在Discord.py中编辑邮件?

Python 如何在Discord.py中编辑邮件?,python,discord,discord.py,Python,Discord,Discord.py,我用它向服务器上的每个人发送dm @bot.command(pass_context = True) @commands.has_permissions(manage_messages=True) async def dm_all(ctx, *, args=None): sended_dms = 0 rate_limit_for_dms = 20 time_to_wait_to_avoid_rate_limit = 60 if args != None:

我用它向服务器上的每个人发送dm

@bot.command(pass_context = True)
@commands.has_permissions(manage_messages=True)
async def dm_all(ctx, *, args=None):
    sended_dms = 0
    rate_limit_for_dms = 20
    time_to_wait_to_avoid_rate_limit = 60

    if args != None:
        members = ctx.guild.members
        for member in members:
            try:
                await member.send(args)
                await ctx.channel.send(" sent to: " + member.name)

            except:
                await ctx.channel.send("Couldn't send to: " + member.name)
            sended_dms += 1
            if sended_dms % rate_limit_for_dms == 0: 
                asyncio.sleep(time_to_wait_to_avoid_rate_limit) 

    else:
        await ctx.channel.send("Please provide a message to send!")
代码是完美的,它的工作也很好。它在dm发送到{member.name}的每个dm之后发送日志,我想要的是在每个日志(即msg)发送到….之后,对于下一个日志,它应该编辑上一条消息。(对不起,我不善于解释:p)

它会在每个dm之后发送一条消息,如下所示, 已发送到{member.name} 然后下一个发送到{member.name}

我想要的是,它不应该一次又一次地发送,而是应该为每个dm一次又一次地编辑第一条消息


如果你能帮忙,我将非常感激

要编辑消息,可以使用
消息。编辑
。以下是一个例子:

random_message = await ctx.send("old message")
await random_message.edit("new message")
此外,如果您查看或其他stackoverflow问题,您可以轻松找到答案。

您可以使用。以下是如何让它在代码中工作:

@client.command(pass_context = True)
@commands.has_permissions(manage_messages=True)
async def dm_all(ctx, *, args=None):
    sended_dms = 0
    rate_limit_for_dms = 20
    time_to_wait_to_avoid_rate_limit = 60

    if args != None:
        members = ctx.guild.members
        firstTime = True
        msg = None
        for member in members:
            if not member.bot:
                try:
                    await member.send(args)
                    if firstTime:
                        msg = await ctx.channel.send(" sent to: " + member.name)
                        firstTime = False
                    else:
                        await msg.edit(content=" sent to: " + member.name)
                except Exception as e:
                    await msg.edit(content="Couldn't send to: " + member.name)
                if sended_dms % rate_limit_for_dms == 0: 
                    await asyncio.sleep(time_to_wait_to_avoid_rate_limit) 
    else:
        await ctx.channel.send("Please provide a message to send!")

还添加了一行忽略bot用户。

您能在我共享的代码中演示如何做到这一点吗@努尔克姆