python - Python discord bot如何将消息与列表进行比较
问题描述
我正在制作一个 python Discord Bot,现在我正试图让他响应列表中的某个消息,但是存在一些问题,因为他只在消息开始文本时才响应(而不是在中间或结尾) . 所以我想弄清楚如何让他比较所有文本并与消息列表匹配,发送文本答案。
Python 3.8.2
代码:
import discord
from discord.ext import commands
from discord.ext.commands import Bot
import asyncio
bot = commands.Bot(command_prefix = "$")
phrases = ["QWACK","KWAK","AARK","KWAAAK"]
@bot.event
async def on_ready():
print ("I'm ready!")
@bot.event
async def on_message(message):
if str(phrases) in message.content:
await message.channel.send("dhbang")
解决方案
我很惊讶机器人的反应xD
str(phrases) 是一个字符串,这个特定的字符串:"["QWACK","KWAK","AARK","KWAAAK"]"
您应该遍历每个单词,并检查该单词是否在消息中。
您还应该考虑在一封邮件中出现的大小写和多个关键字。
推荐阅读
- docker - 通过 Docker 容器中托管的 jenkins 运行 psexec.exe,错误“句柄无效”
- msbuild - 无法加载文件或程序集“Microsoft.Build.Utilities.Core,版本=15.0.0.0
- ios - 保存 UIViewController 状态
- python - 在熊猫列中舍入值的正确方法
- mysql - SQLSTATE [42S22]:找不到列:我的代码中的 1054 列未知
- java - 如何从 Dao 类中获取数据并设置控制器类
- javascript - 发送 ajax POST FormData 对象键和值时未设置
- node.js - Apollo Server 2.6 中的未知类型“上传”
- apache-nifi - NiFi:在我们放入executescript之前,有没有办法逐行执行python代码?
- java - java从SequenceInputStream问题中读取内容