discord - 在 on_message 事件中,discord.py 机器人正在发送垃圾邮件
问题描述
discord.py 有问题。
@client.event
async def on_message(message):
if message.author != message.author:
return
else:
if message == "Buck" or "buck":
await message.channel.send("Yes, he's the Chairman of Dallas!")
它基本上无限重复“是的,他是达拉斯的主席”,这可能会使我因滥用 api 而被禁止,并可能使我无法获得佣金。
解决方案
像这样的表达:
if x == "foo" or "bar" or "baz":
Python 是这样解释的:
if (x == "foo") or ("bar") or ("baz"):
如果第一个表达式(x == "foo")
不为真,则第二个表达式为真("bar")
,所以这个复合条件总是通过。
试试这个:
if x == "foo" or x == "bar" or x == "baz":
或者,甚至更好:
if x in ("foo", "bar", "baz"):
此外,您正在比较整个discord.Message
实例,而不仅仅是内容。
修复您的代码:
if message.content in ("Buck", "buck"):
推荐阅读
- python - 有没有办法同步visdom更新?
- vba - 从组合框中删除项目时,最后一个项目被删除,但文本仍然存在......如何在最后一个项目被删除后使组合框变为空白?
- c# - WPF、XAML:可用空间小于MinWidth时拉伸(带图片)
- openapi - 如何配置 Quarkus 用于 openapi 和健康的路径?
- oracle - 我们如何通过使用执行子句重新创建 TRG_1 触发器来指定 TRG_2 触发器应在 TRG_1 触发器之前执行?
- scala - 当参数是对象类型时,如何在 F# 中要求多个接口?
- javascript - 如何对数组中的混洗元素进行编号?
- python - 如何将 PySpin 与 opencv python 一起使用?
- sightly - Sightly - 仅在有标题时才显示标题标签
- c# - Parsing LSM6DSL raw values