首页 > 解决方案 > Python 如果消息包含

问题描述

下面的代码如果我们输入!message命令 bot 询问消息,当我们输入消息时它会转换为嵌入。

@commands.command(pass_context=True)
async def message(self, ctx):
    message = await self.bot.send_message(ctx.message.channel, "What you want to Send? ")
    reply = await self.bot.wait_for_message(timeout= 60, author=ctx.message.author, channel=ctx.message.channel)

    embed = discord.Embed(title="Something goes here", description="{}".format(reply.content), color=0x029F98)
    await self.bot.send_message(ctx.message.channel, embed=embed)

但在我的on_message我有message.content = message.content.lower()转换为更低的。因此,如果机器人消息包含特定行忽略小写,我添加了一行忽略。

@bot.event
async def on_message(message):
    if "Something goes here" not in message.content:
        message.content = message.content.lower()

    await bot.process_commands(message)

那么如果机器人消息有一些单词,如何忽略小写。

标签: python-3.xdiscord.py

解决方案


如果您希望它忽略任何消息匹配something goes here,则只需使用以下代码:

if "something goes here" not in message.content.lower():    
    # do >something

推荐阅读