问题描述
@pip.command()
async def clear(ctx,amount):
if amount == "all":
await ctx.send("Are you sure you want to delete all messages in this channel?")
async def yes(ctx):
if ctx == "yes":
await ctx.channel.purge(limit=100000000)
这是我的代码。
它向我发送消息,询问我是否确定要删除所有消息,但之后,当我输入“pip yes”(pip 是我的前缀)时它什么也不做,我该如何解决这个问题?
感谢您的帮助!
解决方法
您应该进一步查看client.wait_for。它在不和谐的构建功能中。纯粹!
import asyncio
@client.command()
async def clear(ctx,amount):
if amount == "all":
await ctx.send("Are you sure you want to delete all messages in this channel?")
def check(message):
if message.author == ctx.author:
return ctx.author == message.author # Or just return True
try:
answer = await client.wait_for('message',timeout = 20.0,check = check)
if answer.content == "yes":
await ctx.channel.purge(limit=100000000)
else:
# Do something
except asyncio.TimeoutError:
await ctx.send('Timeout')