如何修复向某人发送dm时的TypeError



我一直在尝试制作一个DM命令来发送消息以及作者提供的消息。但是,我一直收到这个错误:TypeError: send() takes from 1 to 2 positional arguments but 3 were given

这是我现在的代码:

@client.command()
async def sendadm(ctx, user: discord.User, *, message=None):
if ctx.message.author.id == owner_discord_id:
message = message or ""
await user.send(message)
else:
await user.send(message, "nnSent by {ctx.author}")

请注意,User.send()方法是一个实例方法,因此self将被隐式传递,因此您的错误是给出了3个位置参数。(第一个位置参数是self。可选的第二个位置参数为content。(主要问题是您试图将两个不同的值传递给位置参数content

似乎您正在尝试将消息字符串和"nnSent by {ctx.author}"组合起来,所以请参阅下面的";校正的";密码


@client.command()
async def sendadm(ctx, user: discord.User, *, message=None):
if ctx.message.author.id == owner_discord_id:
message = message or ""
await user.send(message)
else:
await user.send(f"{message}nnSent by {ctx.author}")

最新更新