首页 > 解决方案 > 内容 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:“命令”对象没有属性“内容”

标签: pythondiscorddiscord.py

解决方案


不要使用say.content. 变量say不是输入的消息,而是函数的函数/名称。

尝试使用ctx.message.content而不是say.content


推荐阅读