我正在使用它向服务器上的每个人发送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一次又一次地编辑第一条消息。
如果能提供帮助,我将不胜感激!
答案 0 :(得分:1)
您可以使用Message.edit
。您可以通过以下方式在代码中使用它:
@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!")
还添加了一行以忽略漫游器用户。
答案 1 :(得分:0)
要编辑消息,可以使用Message.edit
。这是一个示例:
random_message = await ctx.send("old message")
await random_message.edit("new message")
此外,如果您查看documentation或其他stackoverflow问题,也可以轻松找到答案。