“属性错误:“上下文”对象没有属性“用户”运行命令 Discord.py 时
我正在通道中使用我的代码进行回溯。该命令应该将我选择的 dm 发送给用户,但它只是回复我的消息并显示下面的回溯错误!有人可以帮忙吗?
源代码:
@client.command(aliases=["dm"])
async def DM(ctx, user: discord.User, *, message=None,):
message = message or "This Message is sent via DM"
try:
await ctx.user.send(f"{message}.\n\nRegards,\Real_IceyDev")
await ctx.channel.send(f"{ctx.user.mention}, check your DMs.")
except Exception as jsonError:
await ctx.channel.send(f"{ctx.author.mention}, an error ocurred!\nDeveloper Details:\n```fix\n{repr(jsonError)}\n```\nRecommended fixes: **enable your DMs if you haven't**.")
回溯:AttributeError("'Context'对象没有属性'user'")
I'm getting traceback with my code in the channel. The command is supposed to send a dm of my choice to a user, YET it just replies to my message with that traceback error below! Can anyone help?
Source code:
@client.command(aliases=["dm"])
async def DM(ctx, user: discord.User, *, message=None,):
message = message or "This Message is sent via DM"
try:
await ctx.user.send(f"{message}.\n\nRegards,\Real_IceyDev")
await ctx.channel.send(f"{ctx.user.mention}, check your DMs.")
except Exception as jsonError:
await ctx.channel.send(f"{ctx.author.mention}, an error ocurred!\nDeveloper Details:\n```fix\n{repr(jsonError)}\n```\nRecommended fixes: **enable your DMs if you haven't**.")
Traceback: AttributeError("'Context' object has no attribute 'user'")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,这是一个不言自明的错误。第二件事你没有阅读文档。
基本上,
ctx
没有user
对象。现在,如果您想提及/DM 被调用的用户,请使用以下命令:First thing, this is a self-explained error. Second thing you didn't read the docs.
Basically,
ctx
don't haveuser
object. Now, if you want to mention/DM the invoked user, use this:试试这个:
您只需使用 user.send 而不是 ctx.user.send,因为它不存在。
Try this:
You would just use user.send instead of ctx.user.send because that does not exist.