python - 用 Python 编写 Discord 机器人——当消息只包含一个字母时,如何让它识别?
问题描述
我正在为我的机器人做出反应。每当有人只说字母“f”时,我希望它发送一张图片:
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('f') or message.content.startswith('F'):
await message.channel.send(file=discord.File('f.png'))
但是,只要有人说以“f”开头的内容,此代码就会发送图像。每当有人说仅包含字母“f”的内容时,我希望它发送图像。不知道怎么做,有什么提示吗?
解决方案
这是基本的python
>>> "foo".starswith("f")
True
>>> "foo" == "f"
False
on_message
您可以在事件中使用相同的原则
if message.content.lower() == "f":
# Send the image
推荐阅读
- python - ImportError:无法从“urllib3.connection”导入名称“port_by_scheme”
- java - \app\src\main\res\layout\activity_login.xml:AAPT:错误:文件编译失败
- c++ - 以 8 位数字形式输入日期并显示为英文形式
- javascript - Javascript - 通过 javascript 将 -webkit-overflow-scrolling css 属性设置为正文
- javascript - 将 iframe 调整为嵌入的 facebook 视频的原始高度/纵横比
- python - 我如何定期更改图像并标记值
- ruby - xcversion更新`:NoMethodError:未定义的方法`first'为nil:NilClass
- python - 在 Python Numba/NumPy 中实现的摊销 O(1) 滚动最小值
- android - ActivityCompat 在 android.support.v4.app 上始终未定义
- c# - byte[] 到 fnv1a32 的 0x 十六进制字符串