Python 如果没有被抓到的话

Python 如果没有被抓到的话,python,if-statement,discord,command,discord.py,Python,If Statement,Discord,Command,Discord.py,为什么它不停止也不承认我写的!终止 因此,解释“变量”是discord用户向bot发送的内容。然后我想检查变量。content消息的内容,如果它说!结束命令应停止尝试执行以下操作: def check(m): return m.author == ctx.author and ctx.channel == m.channel for index, i in enumerate(txtare): await ctx.send(f'What is the {txtare[i

为什么它不停止也不承认我写的!终止 因此,解释“变量”是discord用户向bot发送的内容。然后我想检查变量。content消息的内容,如果它说!结束命令应停止

尝试执行以下操作:

def check(m):
        return m.author == ctx.author and ctx.channel == m.channel

for index, i in enumerate(txtare):
    await ctx.send(f'What is the {txtare[index]}')
    try:

        variable = await client.wait_for('message',timeout=time_out, check=check)
        if variable.content == '!end':
            print(variable.content)
            return
        draw.text((x_axis[index], y_axis[index]),codecs.decode(str(variable.content), "unicode_escape"),(0,0,0),font=font2)
    except asyncio.TimeoutError:
        await ctx.send("Time out!")
        return

如果这不起作用,请尝试将discord bot初始化为bot而不是客户端。 您可以这样做:

if variable.content.strip() == '!end':
  ##code
bot是客户端的一个子类,具有额外的功能。例如,为了便于您使用,要检测发送命令的人,您只需执行以下操作:

from discord.ext import commands
bot = commands.Bot(command_prefix='!')
##code
bot.run(TOKEN)

通过使用bot,您可以解锁客户端没有的潜在用途。但是,您需要替换代码,以及任何表示client with bot的内容,例如:client.event->bot.event,并删除if变量.content='!命令“:代码。

欢迎使用SO。我不熟悉discord.py;但是variable.content是否也会包括\n?您能说明您的问题吗?你在做什么?你做了什么?问题是什么?问题是,我希望命令在我做的时候停止!结束了,但不幸的是,结束了!end不是caughtyes@ewong the counts本质上,你可以比较!以结束\n!您可以初始化一个变量,但是您希望bot=commands.bot和client=commands.bot都能工作,这在这里甚至不是问题,因为OP使用的是ctx,很明显他们使用的是commands.bot,它在@client.command中
@bot.command(name='thing_after_prefix_to_activate_command',help='this will explain what it does, available by doing !help')
async def name(message):
  ##code