python-3.x - 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)
那么如果机器人消息有一些单词,如何忽略小写。
解决方案
如果您希望它忽略任何消息匹配something goes here
,则只需使用以下代码:
if "something goes here" not in message.content.lower():
# do >something
推荐阅读
- python - 将 .data 文件加载到 Python 中并将其居中
- xcode - Xcode 如何修复将我的 uilabel 链接到 xib 文件的错误?
- bash - 使用 bash、jq、sed 解析运动数据
- python - Where are application errors logs?
- python - twisted CRITICAL: Unhandled error in Deferred:
- python - AWS Elastic Beanstalk Using Python 2 and Python 3 in error?
- python-3.x - 我在尝试创建 for in 循环时收到 FileNotFoundError
- python - 什么是 PEP:在 pycharm 的这段代码中,预计 2 个空行发现 1 个
- c# - 如果调用者作为 Windows 服务运行,则包含 messagebox.show 的函数无法弹出
- r - 如何根据 R 中的特征名称将一个空间数据集子集为多个空间数据集