【问题标题】:discord py bot send message more than one timediscord py bot 多次发送消息
【发布时间】:2021-06-17 17:46:54
【问题描述】:

这是我的代码:

@bot.command(pass_context = True)
async def spambot(ctx):
    await ctx.author.send("message")
    await ctx.send("check your dms")

这会发送消息,然后发送一个通知。如何多次重复此过程?

【问题讨论】:

  • 你到底想做什么(也许还有那个代码)?

标签: python discord discord.py


【解决方案1】:

我假设你在问如何把它放在一个循环中。

import asyncio

@bot.command(pass_context=True)
async def spambot(ctx):
    for i in range(10): #you can change 10 to any number, this loops the command 10 times
        await ctx.author.send("message")
        await ctx.send("check your dms")
        await asyncio.sleep(1) #this adds a delay so your bot doesn't get rate limited

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-12
    • 1970-01-01
    • 2020-12-01
    • 2021-03-02
    • 2021-06-05
    • 2021-07-26
    • 2020-04-07
    • 2020-12-03
    相关资源
    最近更新 更多