@client.command()
async def spam(ctx):
while True:
time.sleep(2)
await ctx.send("spam")
@client.event
async def on_message(message):
if message.content == "!stop":
# stop spamming 我想要密码停止垃圾邮件,但我不知道怎么做。
发布于 2020-05-22 19:55:29
使用wait_for尝试这个示例
@client.command()
async def spam(ctx):
def check(m):
return m.author == ctx.author and m.channel == ctx.channel
stopped = False
await ctx.send("spam")
while not stopped:
try:
message = await client.wait_for("message", check=check, timeout=2)
stopped = True if message.content.lower() == "!stop" else False
except asyncio.TimeoutError: # make sure you've imported asyncio
await ctx.send("spam")
await ctx.send("spam finished!")参考资料:
https://stackoverflow.com/questions/61955827
复制相似问题