python - 内容 discord.py 的错误
问题描述
@client.command()
@commands.cooldown(1, 5, commands.BucketType.user)
async def say(ctx, *, response):
if "@" in say.content.contains:
await ctx.send("no")
else:
response = response.replace("(", "")
response = response.replace(")", "")
await ctx.send(response)
我正在努力做到这一点,所以如果你输入 .say 那么任何带有 @ 的东西都会取消命令
错误消息:如果say.content.contains中的“@”:AttributeError:'Command'对象没有属性'content'
上述异常是以下异常的直接原因:
Traceback(最近一次调用最后一次):文件“/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py”,第 903 行,invoke await ctx.command.invoke( ctx)文件“/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py”,第 859 行,调用等待注入(*ctx.args,**ctx.kwargs ) 文件“/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py”,第 94 行,在 exc discord.ext.commands.errors 的包装中引发 CommandInvokeError(exc) .CommandInvokeError:命令引发异常:AttributeError:“命令”对象没有属性“内容”
解决方案
不要使用say.content
. 变量say
不是输入的消息,而是函数的函数/名称。
尝试使用ctx.message.content
而不是say.content
推荐阅读
- python - 仅使用有限的编程概念打印帕斯卡三角
- python - 如何遍历txt文件并将值分配给Python中的字典?
- swift - 带有容器视图的滚动视图无法正确调整内容大小
- email - 如何添加为客户下订单的登录 wordpress 用户(销售人员)的用户名
- java - Android Studio 无法识别我的资源目录
- java - 映射器为使用 @JsonIgnore (resttemplate) 注释的字段获取空值
- java - RGB 到 NV21 (YUV420SP) 转换中的 U/V 值是如何计算的?
- excel - 控制图表现怪异
- android - 有没有办法让切换轨道比拇指长?
- machine-learning - 证明多元线性回归模型效率的良好 RMSE(均方根误差)值范围是多少?