为了账号安全,请及时绑定邮箱和手机立即绑定

正在等待消息,但机器人没有响应

正在等待消息,但机器人没有响应

PHP
缥缈止盈 2023-11-09 16:54:08
@client.command()@has_permissions(administrator=True)async def nuke(ctx, channel_name):    channel_id = int(''.join(i for i in channel_name if i.isdigit()))    existing_channel = client.get_channel(channel_id)    await ctx.send("Please confirm nuke: type yes or no")    def check(m):        return m.content == 'yes'    msg = await client.wait_for('message', check=check)    if existing_channel is not None:        await existing_channel.clone(reason="Has been nuked")        await existing_channel.delete()    else:        await ctx.send(f'No channel named **{channel_name}** was found')    def check(s):        return s.content == 'no'    msg = await client.wait_for('message', check=check)    await ctx.send("Nuke has been canceled")我遇到的问题:一旦你说不,机器人应该取消命令,但它不会取消命令。如果您在说“不”后立即说“是”,机器人无论如何都会继续克隆并删除频道。也没有错误消息。如果您需要任何其他信息,请告诉我。
查看完整描述

1 回答

?
幕布斯6054654

TA贡献1876条经验 获得超7个赞

该行不会暂停执行直到满足msg = await client.wait_for('message', check=check)条件吗?m.content == 'yes'这应该效果更好:


@client.command()

@has_permissions(administrator=True)

async def nuke(ctx, channel_name):

    channel_id = int(''.join(i for i in channel_name if i.isdigit()))

    existing_channel = client.get_channel(channel_id)

    await ctx.send("Please confirm nuke: type yes or no")


    def check(m):

        return m.content == 'yes' or m.content == 'no'


    msg = await client.wait_for('message', check=check)


    if msg.content == 'yes':

        if existing_channel is not None:

            await existing_channel.clone(reason="Has been nuked")

            await existing_channel.delete()

        else:

            await ctx.send(f'No channel named **{channel_name}** was found')

    elif msg.content == 'no':

        await ctx.send("Nuke has been canceled")


查看完整回答
反对 回复 2023-11-09
  • 1 回答
  • 0 关注
  • 56 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信