【问题标题】:Waiting for the message, but the bot does not respond等待消息,但机器人没有响应
【发布时间】:2020-10-14 10:34:35
【问题描述】:
@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")

我遇到的问题: 一旦你说不,机器人应该取消命令,但它不会取消命令。如果您在说不之后立即说是,那么机器人将继续克隆并删除频道。也没有错误消息。如果您需要任何其他信息,请告诉我。

【问题讨论】:

    标签: python discord.py


    【解决方案1】:

    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-03-14
      • 2020-02-23
      • 1970-01-01
      • 1970-01-01
      • 2022-12-07
      • 1970-01-01
      • 2020-12-26
      • 2021-03-22
      • 2021-07-19
      相关资源
      最近更新 更多