即使单词的前面或后面有一些字母,也能检测到特定的单词吗?(PYTHON)
这是我用python制作discord机器人的代码(跳过),我想检测“detect”这个词 我成功地检测到了那个单词,但它无法检测出该单词的前面或后面是否有其他字母。 (例如,一些探测到的东西)即使单词的前面或后面有一些字母,也能检测到特定的单词吗?(PYTHON),python,bots,discord,Python,Bots,Discord,这是我用python制作discord机器人的代码(跳过),我想检测“detect”这个词 我成功地检测到了那个单词,但它无法检测出该单词的前面或后面是否有其他字母。 (例如,一些探测到的东西) 是否有任何解决方案可以检测“detect”一词,即使还有其他字母?我认为这应该可以: bot = commands.Bot(command_prefix='#') @bot.event async def on_message(message): if message.content == "
是否有任何解决方案可以检测“detect”一词,即使还有其他字母?我认为这应该可以:
bot = commands.Bot(command_prefix='#')
@bot.event
async def on_message(message):
if message.content == "detect":
await bot.send_message(message.channel, "detected")
您是否尝试过:if“detect”在消息中。内容:请注意,“undetectable”中的“detect”是True
,这可能是您想要的,也可能不是您想要的,特别是因为您提到了“word”。
bot = commands.Bot(command_prefix='#')
@bot.event
async def on_message(message):
if "detect" in message.content:
await bot.send_message(message.channel, "detected")